my C++ solution


  • 0
    Z

    '''
    class Solution {
    public:
    string convert(string s, int numRows) {
    vector<string> strmap(numRows, "");
    string res="";
    if (numRows == 1)
    return s;
    for (int i = 0; i < s.size(); i++){
    int temp = i % (2 * numRows - 2);
    if (temp<numRows)
    strmap[temp].push_back(s[i]);
    else
    strmap[2 * numRows - temp-2].push_back(s[i]);
    }
    for (int i = 0; i < strmap.size(); i++)
    {
    string sd = strmap[i]; res += sd;
    }
    return res;
    }
    };
    '''


Log in to reply
 

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