Skip to content

Commit f9fe8f4

Browse files
author
cpppy
authored
Create 6_ZigZag_Conversion.cc
1 parent 0655fbc commit f9fe8f4

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed

6_ZigZag_Conversion.cc

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
class Solution {
2+
public:
3+
string convert(string s, int numRows) {
4+
if(s==""||numRows==1) return s;
5+
int len=s.size();
6+
vector<string> partition(numRows,"");
7+
int i=0;
8+
int j=0,a;
9+
while(len){
10+
partition[j]+=s[i];
11+
i++;
12+
if(j==0) a=1;
13+
if(j==numRows-1) a=-1;
14+
j+=a;
15+
len--;
16+
}
17+
string result;
18+
for(int i=0;i<numRows;++i){
19+
result+=partition[i];
20+
}
21+
return result;
22+
}
23+
};

0 commit comments

Comments
 (0)