Beats 92%


  • 0
    A
    public boolean isPalindrome(int x) {
    	return (x < 0) ? false : x == reverse(x);
    }
    
    int reverse(int x) {
    	int y = 0;
    	while (x != 0) {
    		y = y + x % 10;
    		x = x / 10;
    		if (x != 0)
    			y = y * 10;
    	}
    	return y;
    }

Log in to reply
 

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