Runtime Error


  • 0
    T

    Any ideas that why I got "Runtime Error" when submit the code.

    class Solution {
    public:
        string reverseString(string s) {
            int i=0;
            string temp=s;
            string::iterator It;
            for(It=s.end()-1;It!=s.begin();It--){
                temp[i]=*It;
                i++;
            }
            temp[i]=*It;
            return temp;
        }
    };
    

  • 0
    P

    What happens when u pass an empty string?
    It is uninitialized and you are dereferencing


Log in to reply
 

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