Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
class Solution {
public:
string convert(string s, int num) {
int len = s.size();
string finalStr;
if(num == 1||len<=1) return s;
int k = 2 * num - 2;
for(int i = 0; i< num; i++)
{
for(int j = 0; i + j<len; j = j + k)
{
finalStr.push_back(s[i+j]);
// get rid of the first and last line
if(i!=0 && (i!= num - 1) && (j + k - i < len);
finalStr.push_back(s[j+k - i]);
}
}
return finalStr;
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment