Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions LeetCode Questions/C++/1. Problems/zigzag_Conversion.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
class Solution {
public:
string convert(string s, int numRows) {
string ans;
vector <string> tmp(numRows);
//create strings for each row
int i=0, n=s.size();
while(i<n){
for(int j=0;j<numRows && i<n; j++, i++) tmp[j] += s[i];
//add for our strings character when we move down
for(int j=numRows - 2;j>0 && i<n; j--, i++) tmp[j] += s[i];
//add for our strings character when we move up exept first and last string
}
for(int j=0;j<numRows; j++) ans += tmp[j];
//combain together our strings
return ans;
}
};