您的位置:首页 > 其它

LeetCode: Palindrome Number

2013-09-29 09:28 337 查看
一般都需要用base来计数,排除数字中0的影响

class Solution {

public:

bool isPalindrome(int x) {

// Start typing your C/C++ solution below

// DO NOT write int main() function

if(x<0)

return false;

int base=1,right=0,left=x;

while(left>=base){

right = 10*right+left%10;

left /= 10;

base *= 10;

}

if(left==right||right/10==left)

return true;

return false;

}
};
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: