Passed with 1 submission without running/compiling first : )


  • 0
    F

    Feels so good.

    class Solution {
    public:
        string convert(string s, int rows) {
            if (rows <= 1)
                return s;
            string result;
            int base = (rows - 1) * 2;
            for (int i = 0 ; i < rows; ++i)
            {
                int step = 2 * i;
                for (int j = i; j < s.size(); j += step)
                {   
                    result.push_back(s[j]);
                    step = base - step;
                    if (step == 0)
                        step = base;
                }
            }
            return result;
        }
    };
    
    

Log in to reply
 

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