My ez understanding c++ solution


  • 10
    Z
    string convert(string s, int numRows) 
    {
        if(numRows==1)return s;
        string t;
        vector<string> vec(numRows,"");
        int i=0,j=0;
        while(i<s.length())
        {
            while(j<numRows-1&&i<s.length())
            {
                vec[j++] += s[i++];
            }
            while(j>0&&i<s.length())
            {
                vec[j--] += s[i++];
            }
        }
        for(auto i=vec.begin();i!=vec.end();i++)
        {
            t += *i;
        }
        return t;
    }

  • 0
    L

    your solution is amazing!


  • 0

    Very straightforward solution!


Log in to reply
 

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