C++ solution


  • 0
    L
    class Solution {
    public:
        int reverse(int x) {
            int y=0;
            while(x)
            {
              if (y > INT_MAX/10 || y < INT_MIN/10)
                    return 0;
              y=y*10+x%10;
              x=x/10;
            }
            return y; 
        }
    };
    

  • 0
    E

    I like your solution but I'm not sure how this one accounts for negative numbers.


Log in to reply
 

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