5 lines c++, just for fun


  • 0
    P
    string convert(string s, int numRows) {
        string ans = s;
        for (int i = 0, cnt = 0;i < numRows;++i)
            for (int j = i, c = 0;j < s.size();j += max(((i!=numRows-1&&(i==0 || ++c % 2))?(numRows-1)*2-2*i:2*i),1))
                ans[cnt++] = s[j];
        return ans;
    }

Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.