A simple Java solution


  • 0
    H

    '''
    public class Solution {
    public int reverse(int x) {
    int y = 0;
    int n;
    while (x != 0) {
    n = x % 10;
    if (y > Integer.MAX_VALUE / 10 || y < Integer.MIN_VALUE / 10) {
    return 0;
    }
    y = y * 10 + n;
    x /= 10;
    }
    return y;
    }
    }
    '''


Log in to reply
 

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