Can anybody explain why output limit exceeded error is occurred?


  • 0
    H
    class Solution {
    public:
        string convert(string s, int nRows) {
          string new_str = "";  
          if ((nRows<=0) || (s.size()==0)){return "";}
          if (s == "") {
              return new_str;
          }        
          if (nRows == 1) {
              return s;
          }
          if (nRows>=s.length()){return s;}
          vector<vector<char>> mat(nRows);
          vector<vector<char>>::iterator it;
          vector<char>::iterator it_in;
          int i = 0;
          int row  = 0, col = 0;
          
          while (i<s.length()) {
            while (row < nRows) {
              mat[row].push_back(s[i]);
              i++;
              row++;
            }
            row = row - 2;
            col = col + 1;
            while (row >= 0) {
              mat[row].push_back(s[i]);
              i++;
              row--;
              col++;
            }
            row = row + 2;
            col --;
        
          }
           for(it = mat.begin();it!=mat.end();it++){
            for(it_in = it->begin(); it_in!=it->end();it_in++) {
                new_str+=*it_in;
            }
        }
        return new_str;
        }
    };

Log in to reply
 

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