Java Solution for isPalindrome


  • -2
    N
     public class Solution {
            public boolean isPalindrome(int x) {
                int original = x;
                int reverse = 0;
                while(x>0){
                  reverse = reverse * 10  + x%10;
                  x = x/10;
                }
                if(reverse==original){
                    return true;
                }
                else{
                    return false;
                }
            }
        }

Log in to reply
 

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