Palindrome Number --回文整数

来源:互联网 发布:怎样才能做淘宝客推广 编辑:程序博客网 时间:2024/05/18 16:56

问题:链接

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

解答:

不能用额外的元素,但是几个变量是可以用的。

如果是负数,直接返回false

否则  见代码。


代码:

class Solution {public:    bool isPalindrome(int x) {       if(x < 0)       {           return false;       }       int t, w;       t = x, w = 0;       while(t)       {           w = w*10 + t%10;           t /= 10;       }       if(w == x)         return true;       else        return false;            }};


0 0
原创粉丝点击