Maple's Blog.

Leetcode-09

字数统计: 72阅读时长: 1 min
2019/04/04 Share

bool isPalindrome-链接

实现的代码如下:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
class Solution {
public:
bool isPalindrome(int x) {
long long ans=0,sign,x1=x;//定义long long类型以防溢出
sign=(x<0)? -1:1;
while(x)
{
ans=ans*10+x%10;
x/=10;
}
ans*=sign;
if(ans==x1)
return true;
else
return false;

}
};

一道很水的题……

CATALOG