美文网首页
9. Palindrome Number

9. Palindrome Number

作者: i_Eloise | 来源:发表于2018-01-20 19:47 被阅读0次
  • first attempt
class Solution {
public:
    bool isPalindrome(int x) {
        //reverse number is the same
        if(x<0)
            return false;
        if(x == 0)
            return true;
        int same = x;
        int result = 0 ;
        int bit;
        while(same!=0)
        {
            bit = same%10;
            result = result*10+bit;
            same/=10;
        }
        return (result==x);
    }
};

相关文章

网友评论

      本文标题:9. Palindrome Number

      本文链接:https://www.haomeiwen.com/subject/rnytaxtx.html