Accepted Java Solution without String Operations


  • 0
    Z
    public class Solution {
            public int reverse(int x) {
                long num = 0;
                while(x != 0){
                    int temp = x % 10;
                    num += temp;
                    x /= 10;
                    if(x != 0)
                        num *= 10;
                }
                if(num > 2147483647 || num < -2147483647)
                    return 0;
                else
                    return (int)num;
            }
    }

Log in to reply
 

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