SIMPLE Java solution [ACCEPTED at 564ms]


  • 0
    A

    Basically I am reversing the input integer and checking if the reverse is equal to input int

      public boolean isPalindrome(int i) {
           	if (i<0) return false;
    		int input = i; 
    		int rev = 0;
    		while (i > 0) {
    			rev = rev * 10 + (i % 10);
    			i /= 10;
    		}
    		if (rev == input)
    			return true; 
    		else 
    			return false;
        }

  • 2
    S

    if i=1147483647, then rev=7463847411 > Integer.MAX_VALUE


Log in to reply
 

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