Files
dsa-competitive-programming/leetcode/lc6/zigzag.cpp
T
2026-01-29 01:04:37 +05:30

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;
}
};