Java Solution only 6 lines code


  • 0
    W

    Just use the StringBuffer's reverse function;

    class Solution {
        public boolean isPalindrome(int x) {
            StringBuffer sb=new StringBuffer(x+"");
            if(sb.toString().equals(sb.reverse().toString()))
                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.