Is this a valid solution


  • 0
    A

    Here is the code I find online:

    public class Solution {
       public boolean isPalindrome(int x) {
            if(x<0){
            	return false;
            }
            return x == reverse(x);
        }
        public int reverse(int x){
        	int rst=0;
        	while(x!=0){
        		rst = rst*10 + x%10;
        		x/=10;
        	}
        	return rst;
        }
    

    }

    And will this be a cheat? Because it doesn't consider the situation that the reverse number might be overflow.


  • 1
    C

    If a number's reverse number would overflow, then it must not be a palindrome number.
    The maximum 32-bit integer is 2147447412.


Log in to reply
 

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