Skip to content

Instantly share code, notes, and snippets.

@mountop
Created March 19, 2014 02:23
class Solution {
public:
string convert(string s, int nRows) {
if(s.size()<=0) return s;
if(nRows<=1) return s;
string ret;
for(int i=0; i<nRows; i++){
for(int j=0, index=i; index<s.size(); j++, index = (2*nRows-2)*j+i){
ret.append(1, s[index]);
if(i==0 || i==nRows-1) continue;
index = index + (nRows-i-1)*2;
if(index<s.size())
ret.append(1, s[index]);
}
}
return ret;
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment