-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathleetcode06.cpp
More file actions
39 lines (37 loc) · 906 Bytes
/
leetcode06.cpp
File metadata and controls
39 lines (37 loc) · 906 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
33
34
35
36
37
38
39
#include <iostream>
#include <string>
#include <cstring>
using namespace std;
class Solution {
public:
string convert(string s, int numRows) {
string ans="";
if(numRows==1) return s;
for(int i=0;i<numRows;i++){
for(int j=i;j<s.length();){
if(i==0||i==numRows-1){
ans = ans+s[j];
j+=numRows*2-2;
}
else{
if(j==i){
ans = ans+s[j];
}
j+=numRows*2-2;
if(j>numRows&&((j-2*i)<s.length()))
ans=ans+s[j-2*i];
if(j<s.length()){
ans = ans+s[j];
}
}
}
}
return ans;
}
};
int main()
{
Solution s;
cout<<s.convert("ABCD",3);
return 0;
}