题解 | #回文数字#

回文数字

http://www.nowcoder.com/practice/35b8166c135448c5a5ba2cff8d430c32

数学

class Solution {
public:
    /**
     * 
     * @param x int整型 
     * @return bool布尔型
     */
    bool isPalindrome(int x) {
        // write code here
        if(x < 0) return false;
        int ans = 0;
        while(x > ans){
            ans = ans * 10 + x % 10;
            x /= 10;
        }
        return ans == x || ans / 10 == x;
    }
};
全部评论

相关推荐

饼子吃到撑:当我看到外企的时候,我就知道这大概率可能是真的
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客企业服务