码迷,mamicode.com
首页 > 其他好文 > 详细

题目:回文数

时间:2018-06-12 16:09:17      阅读:137      评论:0      收藏:0      [点我收藏+]

标签:const   res   返回   就是   style   speed   lse   false   sync   

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

 

题目:回文数

标签:const   res   返回   就是   style   speed   lse   false   sync   

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

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!