leetcode 9: Palindrome Number

来源:互联网 发布:java期末考试题库 编辑:程序博客网 时间:2024/06/08 02:52

Reverse the number and compare it with the original one.

class Solution {public:    bool isPalindrome(int x) {        int old_x=x;        int new_x=0;        while(x>0)        {            if((INT_MAX-x%10)/10<new_x)                return false;            new_x=new_x*10+x%10;            x/=10;        }        return new_x==old_x;    }};


0 0
原创粉丝点击