c++ solution


  • 0
    B
    class Solution {
    public:
        string convert(string s, int numRows) {
            vector<string> row(numRows,"");
            int i=0,j=0;
            if(numRows==1) return s;
            while(j<s.length()){
                while(j<s.length() && i<numRows-1) row[i++]+=s[j++];
                
                while(j<s.length() && i>0) row[i--]+=s[j++];
                
            }
            string result="";
            for(string st:row) result+=st;
            return result;
        }
    };
    

Log in to reply
 

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