leetcode— 9. Palindrome Number

来源:互联网 发布:阿里云rds逻辑备份 编辑:程序博客网 时间:2024/06/12 00:22

Determine whether an integer is a palindrome. Do this without extra space.

class Solution {public:bool isPalindrome(int x) {int a, b, tmp;int i = 0;a = 0;b = (x);while (b > 0)   //负数不是回文,a=x的反转{tmp = a;a *= 10;a += b % 10;   if((a- b % 10)/10!=tmp)   //越界检查{break;}b = b / 10;i++;}return  a == abs(x);}};


原创粉丝点击