Solution by C++( convert data type)


  • 0
    A
    class Solution {
    public:
    int reverse(int x) {
        string s = to_string(x);
        if (x >= 0)
        {
            std::reverse(s.begin(), s.end());
        }
        else 
        {	
            std::reverse(s.begin() + 1, s.end());
        }
        long long ans = stoll(s);
        if (abs(ans) >= INT_MAX)
            return 0;
        else
            return ans;
        }
    

    };


Log in to reply
 

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