mirror of
https://github.com/Manoj-HV30/dsa-competitive-programming.git
synced 2026-05-16 19:35:22 +00:00
25 lines
655 B
C++
25 lines
655 B
C++
class Solution{
|
|
public:
|
|
string convert(string s,int numrows){
|
|
if(numrows == 0|| numsrows>=s.length())
|
|
return s;
|
|
vector<vector<char>> rows(numrows);
|
|
int index = 0, direc = 1;
|
|
|
|
for(char c: s){
|
|
rows[index].push_back(c);
|
|
if(index == 0)
|
|
direc =1;
|
|
else if(index == numrows -1)
|
|
direc = -1;
|
|
index+=direc;
|
|
}
|
|
string res;
|
|
for(const auto &row : rows)
|
|
for(char c : row)
|
|
res+=c;
|
|
|
|
return res;
|
|
}
|
|
};
|