C++ , 9ms, easy no math


  • 0
    B
    int reverse(int x) {
        bool negative = false;
        if(x < 0)
            negative= true;
        string s = to_string(x), t;
        for(int i = s.size()-1; i>=0; i--)
            t+=s[i];
        long long temp = stol(t);
        if(negative)
            temp*=-1;
        return temp >=INT_MAX||temp<=-INT_MAX ? 0 : temp;
    }

Log in to reply
 

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