12ms JAVA Solution


  • 0
    X
    public boolean isPalindrome(int x) {
    	if (x < 0)
    		return false;
    	int i = 1;
    	while (true) {
    		if (i > x / 10)
    			break;
    		i *= 10;
    	}
    	for (int j = i; j >= 1; j /= 100) {
    		if (x / j != x % 10)
    			return false;
    		x = (x - x / j * j) / 10;
    	}
    	return true;
    }

Log in to reply
 

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