LeetCode 9. Palindrome Number

来源:互联网 发布:产品经理流程图软件 编辑:程序博客网 时间:2024/06/06 08:36

题意

判断一个数是不是回文数

解题思路

1.负数没有回文数
2.一个整数的反转数可能会超出int范围

参考代码

public class Solution {    public boolean isPalindrome(int x) {        if (x < 0) return false;        long y = 0, tmp = x;        while (x != 0){            y = y * 10 + x % 10;            x /= 10;        }        if (tmp == y) return true;        return false;    }}
原创粉丝点击