Why a Runtime Error occurs on my code?


  • 0
    L

    There is a Runtime Error for the case "AB" and 4, could anyone tell me anything wrong?

    class Solution {
    public:
        string convert(string s, int numRows) {
            vector<string> zz(numRows, "");
            int step = 1;
            for (int i=0, row=0; i<s.size(); ++i) {
                if (row == 0)
                    step = 1;
                else if (row == numRows-1)
                    step = -1;
                zz[row] += s[i];
                row += step;
            }
            
            string res = "";
            for (int i=0; i<zz.size(); ++i) {
                res += zz[i];
            }
            return res;
        }
    };

Log in to reply
 

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