Reverse Integer Solution

mail@pastecode.io avatar
unknown
java
2 months ago
395 B
0
Indexable
Never
class Solution {
    public int reverse(int x) {
        int reversedInt = 0;
        while(x!=0){
            int digit = x%10;

            if(reversedInt < Integer.MIN_VALUE/10 || reversedInt > Integer.MAX_VALUE/10){
                return 0;
            }
            reversedInt = (reversedInt * 10) + digit;
            x = x/10;
        }
        return reversedInt;
    }
}
Leave a Comment