9. Palindrome Number

题目链接:https://leetcode.com/problems/palindrome-number/

解题思路:

目标:判断数字是不是回文数字

首先如果是负数,肯定不是回文数字。

然后将数字翻转,直接比较这两个数字是否相等。

 1 class Solution {
 2     public boolean isPalindrome(int x) {
 3         
 4         
 5         int res=0;
 6         int first=x;
 7         
 8         if(x<0)
 9         {
10             return false;
11         }
12         else
13         {
14             while(x!=0)
15             {
16                 res=res*10+x%10;
17                 x/=10;
18             }
19             if(res==first)
20                 return true;
21         }
22         return false;
23         
24     }
25 }
原文地址:https://www.cnblogs.com/wangyufeiaichiyu/p/10826890.html