Got RunTime Error, but runs okay in local IDE, why??


  • 1
    R

    Here is my code, it got RunTime Error on test case: "AB, 2"

    I tested on local IDE, didn't show any error, please give me some hints, why????

    `class Solution {
    public:
    string convert(string s, int nRows) {

           if(s.empty())  return string("");
           
           string tmp;
           vector<string> ans(nRows, tmp);
          
           int currentRow=0;
           int i=0;
           bool increase=true;
           while(i<s.length()){
               ans[currentRow] += s[i++];
               if(increase) currentRow++;
               else currentRow--;
               if(currentRow == nRows-1) increase = false;
               else if(currentRow == 0)  increase = true;
           }//while
    
           string result("");
           for(int j=0;j<ans.size();++j)
               result += ans[j];
           return result;
    }
    

    };`


  • 0
    S

    Pay attention to "Writing code? Select all code block then click on the {} button to preserve code formatting.” above text editor.


Log in to reply
 

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