Code fails with "Runtime Error" with submit solution only!


  • 0
    S
    string convert(string s, int numRows) {
    
           if (numRows == 0 || numRows == 1) return s;
            
           int row{0};
           std::string result{""};
           std::vector<std::string> zzs{numRows, ""};
      
           bool reverse{false};
           for (auto const& ch : s)
           {
               zzs[row].push_back(ch);
               
               if (row < numRows && !reverse) ++row;
               if (row > 0 && reverse) --row;
               
               if (row == numRows - 1) {reverse = true;}
               if (row == 0) {reverse = false;}
           }
           
           for (auto const& str : zzs) 
            result += str;
            
           return result;
        }
    

    Whats wrong?, it fails with Input {"AB", 4} when I try to "Submit Solution", but works with "Run Code".


Log in to reply
 

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