Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVA

check palindrome in java

class Solution {
    public boolean isPalindrome(int x) {
        if(x < 0)
            return false;

        return x == reverseNum(x);

    }
    private static int reverseNum(int num){
        int rev = 0;
        while(num>0){
            int digit = num%10;
            rev = (rev * 10) + digit;
            num = num/10;
        }
        return rev;
    }
}
Source by leetcode.com #
 
PREVIOUS NEXT
Tagged: #check #palindrome #java
ADD COMMENT
Topic
Name
8+9 =