首页 > 其他 > 详细

题目:回文数

时间:2018-06-12 15:46:42      阅读:247      评论:0      收藏:0      [点我收藏+]

看到这道题我第一个想到的就是之前的翻转整数的题,然后根据题目条件我决定先把负数跟一位数的返回,然后把剩下情况翻转整数,最后比较翻转的结果跟原来的结果,相同返回true。

static const auto io_speed_up = []()
{
    std::ios::sync_with_stdio(false);
    cin.tie(nullptr);
    return 0;
}();

class Solution {
public:
    bool isPalindrome(int x) {
        if (x < 0)
            return false;
        if (x < 10)
            return true;
        int res  = 0;
        for(int temp = x; temp > 0; temp /= 10)
            res = res * 10 + temp % 10;

        if (x == res)
            return true;
        else
            return false;
    }
};

 

题目:回文数

原文:https://www.cnblogs.com/change4587/p/9172999.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!