Solution in Java


  • 0
    R

    """
    class Solution {
    public int reverse(int x) {
    if(x==0)
    return 0;
    boolean neg = (x<0)?true:false;
    if(neg)
    x = x*-1;
    int rev = 0;
    while(x>0) {
    if(rev > 0 && Integer.MAX_VALUE/rev < 10)
    return 0;
    rev = (rev10) + (x%10);
    x = x/10;
    }
    if(neg)
    rev = rev
    -1;
    return rev;
    }
    }
    """


Log in to reply
 

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