my simple and short c++ solution


  • 0
    H

    class Solution {
    public:
    string convert(string s, int numRows) {
    if(numRows == 0)
    return "";
    else if(numRows == 1)
    return s;
    string res;
    int cycle = 2*numRows-2;
    for(int i = 0; i < numRows; i++){
    for(int j = 0; j < s.length(); j+=cycle){
    if(j+i < s.length())
    res += s[j+i];
    if(i > 0 && i < numRows-1 && j+cycle-i < s.length())
    res += s[j+cycle-i];
    }
    }
    return res;
    }
    };


Log in to reply
 

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