AUG!!! Let's do some try catch POKE MON!!!


  • 0
    // Remember that the original number is in the normal range of Integer. 
    //So if the reverse of it overflows, return false;
    public class Solution {
        public boolean isPalindrome(int x) {
            if(x < 0) return false;
            if(x == 0) return true;
            try{
                int copy = x;
                int reverse = 0;
                while(x > 0)
                {
                    reverse *= 10;
                    reverse +=x%10;
                    x /= 10;
                }
                if(copy == reverse)
                    return true;
            }
            catch(Exception e)
            {
                return false;
            }
            return false;
        }
    }
    

Log in to reply
 

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