My C++ Solution


  • 0
    class Solution {
    public:
        string convert(string s, int nRows) {
            if (nRows <= 1) return s;
    		vector<string>temp(nRows);
    		string res;
    		int index;
    		for (int i = 0; i < s.size(); i++){
    			index = i % (2 * nRows - 2) + 1;
    			index = index <= nRows ? index : (2 * nRows -index);
    			temp[index-1] += s[i];
    		}
    		for (int i = 0; i < nRows; ++i)
    			res += temp[i];
    		return res;
        }
    };

Log in to reply
 

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