【leetcode】Palindrome Number

来源:互联网 发布:linux下使用anaconda 编辑:程序博客网 时间:2024/05/16 18:49
class Solution {public:    bool isPalindrome(int x) {        // Note: The Solution object is instantiated only once and is reused by each test case.        if(x<0)            return false;        if(x==0)            return true;                int oldVal=x;        int newVal=0;        while(x>0)        {            newVal=newVal*10+x%10;            x/=10;        }        return oldVal==newVal;    }};

原创粉丝点击