c++ 16ms


  • 0
    H

    string convert(string s, int numRows) {
    string res;
    if (numRows == 1) return s;
    int inval = 2* numRows - 2;
    for (int i = 0; i < numRows; i++){
    int num = i;
    int row = i;
    while (num < s.size()){
    res.push_back(s[num]);
    num = num + (inval - 2 * (row % (numRows-1)));
    if (!(row == 0 || row == (numRows - 1)) && num < s.size() ){
    res.push_back(s[num]);
    num = num + (2 * row);
    }
    }
    }
    return res;
    }


Log in to reply
 

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