细节 Palindrome Number

来源:互联网 发布:网络继电器的工作原理 编辑:程序博客网 时间:2024/06/05 05:55

细节:

左右位数依次比较,全部相同则是回文数;否则不是。


class Solution {public:    bool isPalindrome(int x) {        if(x < 0) return false;        int d = 1;        while(x/d >= 10) d *= 10;        while(x > 0) {            int left = x / d;            int right = x % 10;            if(left != right) {                return false;            }            x = x % d / 10;            d = d / 100;        }        return true;    }};


0 0
原创粉丝点击