-
Notifications
You must be signed in to change notification settings - Fork 3
/
day4.cpp
32 lines (31 loc) · 821 Bytes
/
day4.cpp
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) {
vector<string> answer(numRows,"");
if(numRows==1) return s;
int index = 0;
int ptr = 0;
int size = s.size();
while(index < size){
int i;
for(i=index;i<index+numRows;i++){
if(i<=size-1){
answer[ptr] += s[i];
ptr++;
}else break;
}
index = i; ptr-=2;
while(index<size && ptr>0){
answer[ptr] += s[index];
index++;
ptr--;
}
}
string final_string = "";
for(auto item:answer){
cout<<item<<" ";
final_string += item;
}
return final_string;
}
};