Leetcode Palindrome Number

来源:互联网 发布:微商和淘宝哪个挣钱 编辑:程序博客网 时间:2024/06/08 08:47

Determine whether an integer is a palindrome. Do this without extra space.

Difficulty: Easy


public class Solution {    public boolean isPalindrome(int x) {        if(x<0) return false;        StringBuilder sb = new StringBuilder("");        while(x != 0){            sb.append(Integer.toString(x%10));            x = x/10;        }        String s1 = sb.toString();        return (s1.equals(sb.reverse().toString()));    }}


0 0