-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathleet6.cpp
More file actions
32 lines (32 loc) · 966 Bytes
/
Copy pathleet6.cpp
File metadata and controls
32 lines (32 loc) · 966 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
class Solution {
public:
string convert(string s, int numRows) {
int mm = 2*numRows-2 ;
if(mm==0){
return s ;
}
int t = s.length()/mm +1 ;
char* str = new char[s.length()+1] ;
//line 0
int id ;
for(int i=0 ;i<t ;i++){
if(i*mm<s.length())
str[id++] = s[i*mm] ;
}
for(int ll=1 ;ll<numRows-1 ;ll++){
for(int i=0 ;i<t ;i++){
if(i*mm+ll < s.length())
str[id++] = s[i*mm+ll] ;
if(i*mm+mm-ll <s.length())
str[id++] = s[i*mm+mm-ll] ;
}
}
for(int i=0 ;i<t ;i++){
if(i*mm+numRows-1 < s.length())
str[id++] = s[i*mm+numRows-1] ;
}
str[id] = '\0' ;
string res(str);
return res ;
}
};