leetcde 9 Palindrome Number
Posted 王坤1993
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了leetcde 9 Palindrome Number相关的知识,希望对你有一定的参考价值。
class Solution {
public:
bool isPalindrome(int x) {
//negative number
if(x < 0)
return false;
int len = 1;
while(x / len >= 10)
len *= 10;
while(x > 0) {
//get the head and tail number
int left = x / len;
int right = x % 10;
if(left != right)
return false;
else {
//remove the head and tail number
x = (x % len) / 10;
len /= 100;
}
}
return true;
}
};
以上是关于leetcde 9 Palindrome Number的主要内容,如果未能解决你的问题,请参考以下文章