LeetCode-10(回文检测)

来源:互联网 发布:windows10激活软件 编辑:程序博客网 时间:2024/06/10 12:27

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


class Solution {public:    bool isPalindrome(int x) {        if(x<0 || (x!=0 && x%10==0))  return false;  //个位是0肯定不是回文        int sum = 0;        while(x > sum){            sum = sum*10 + x%10;            x=x/10;        }        return (sum == x)||(x == sum/10);    }};


0 0