Your runtime beats 95.51% of java submissions.(sometimes 10ms)


  • 4

    It compares half of the num of length is OK

    public class Solution {
        public boolean isPalindrome(int x) {
    		if (x < 0)
    			return false;
    		int y = 0, x1 = 1;
    		while (x / x1 != 0) {
    			y = y * 10 + x % 10;
    			x /= 10;
    			x1 *= 10;
    		}
    		return y < 10 * x ? y == x : y / 10 == x;
    	}
    }

Log in to reply
 

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