LeetCode-4

来源:互联网 发布:手机动作特效软件 编辑:程序博客网 时间:2024/06/06 00:10

Palindrome Number(回文,不允许extre space)


72ms 


class Solution {public:    bool isPalindrome(int x) {        if(x<0){return false;}                int tail = 0;        int bit = 0;        int tmp = x;                while(tmp != 0){            tmp = tmp/10;            bit ++;        }                if(bit == 1) return true;                tmp = x;        int a = 0;        for(int i = 0; i<bit/2; i++){            a = tmp%10;            tail = tail*10+a;            tmp = tmp/10;        }                if(bit%2 == 1) tmp = tmp/10;                if(tmp == tail){return true;}                return false;            }};

0 0
原创粉丝点击