My answer in Java. Handle big number.


  • 0
    L
    public boolean isPalindrome(int x) {
            if (x < 0)
    			return false;
    		int root = (int) Math.sqrt(x);
    		int temp = x % 10;
    		while (root / 10 != 0) {
    			temp = temp * 10 + x / 10 % 10;
    			x = x / 10;
    			root = root / 10;
    		}
    		return (x == temp || x / 10 == temp);
    }

Log in to reply
 

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