60ms c# accepted solution


  • 2
    X
    public class Solution {
    public int Reverse(int x) {
        bool neg = x < 0 ? true : false;
        if (neg)
            x *= -1;
        int result = 0;
        while ( x > 0)
        {
            if (result > 0 && int.MaxValue / result < 10)
                return 0;
            result *= 10;
            result += (x % 10);
            x /= 10;
        }
        if (neg)
            result *= -1;
        return result;
    }
    

    }


Log in to reply
 

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