19ms beats 41%


  • 0
    A

    0_1479010189674_Capture.PNG

    '''
    class Solution {
    public:
    string convert(string s, int numRows) {

        if (numRows <= 1)
            return s;
        
        int _BOTTOM = numRows - 1;
        int _TOP = 0;
        int currentDepth = _TOP;
        bool goUp = false;
        std::string final;
        vector<string> rows(numRows,"");
        
        for (int i = 0; i < s.length(); i++){
            rows[currentDepth] += s[i];
            if ((currentDepth) < _BOTTOM && !goUp){
               currentDepth++;
            }
            else if (currentDepth == _BOTTOM){
                goUp = true;
                currentDepth--;
            }
            else if (currentDepth != _TOP && goUp){
                currentDepth--;
            }
            else if (currentDepth == _TOP){
                goUp = false;
                currentDepth++;
            }
        }
        
        for (string str:rows) 
            final += str;
        return final;
    }
    

    };
    '''


Log in to reply
 

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