题目

判断一个数字是不是回文数字,即最高位与最低位相同,次高位与次低位相同,...

解法

求出数字的位数,然后依次求商和求余判断是否相等。

代码

 class Solution {
public:
bool isPalindrome(int x) {
if(x < )  //负数有符号,肯定不是回文数
return false; int d = ;
while(x / d >= )  //d与x位数相同
d *= ; while(x)
{
if(x/d != x%)  //比较最高位和最低位是否相等
return false;
x = x % d / ;  //去掉最高位和最低位
d /= ; //d相应转换
} return true;
}
};

LeetCode题解——Palindrome Number的更多相关文章

  1. leetcode题解||Palindrome Number问题

    problem: Determine whether an integer is a palindrome. Do this without extra space. click to show sp ...

  2. Leetcode 9. Palindrome Number(水)

    9. Palindrome Number Easy Determine whether an integer is a palindrome. An integer is a palindrome w ...

  3. Leetcode练习题 Palindrome Number

    9. Palindrome Number Question: Determine whether an integer is a palindrome. An integer is a palindr ...

  4. leetcode 9 Palindrome Number 回文数

    Determine whether an integer is a palindrome. Do this without extra space. click to show spoilers. S ...

  5. LeetCode 9. Palindrome Number (回文数字)

    Determine whether an integer is a palindrome. Do this without extra space. 题目标签:Math 题目给了我们一个int x, ...

  6. Leetcode 9. Palindrome Number(判断回文数字)

    Determine whether an integer is a palindrome. Do this without extra space.(不要使用额外的空间) Some hints: Co ...

  7. [LeetCode][Python]Palindrome Number

    # -*- coding: utf8 -*-'''__author__ = 'dabay.wang@gmail.com'https://oj.leetcode.com/problems/palindr ...

  8. LeetCode——9. Palindrome Number

    一.题目链接:https://leetcode.com/problems/palindrome-number/ 二.题目大意: 给定一个整数,判断它是否为一个回文数.(例如-12,它就不是一个回文数: ...

  9. 蜗牛慢慢爬 LeetCode 9. Palindrome Number [Difficulty: Easy]

    题目 Determine whether an integer is a palindrome. Do this without extra space. Some hints: Could nega ...

随机推荐

  1. C语言指针的概念

    在计算机中,所有的数据都是存放在存储器中的.一般把存储器中的一个字节称为一个内存单元,不同的数据类型所占用的内存单元数不等,如整型量占2个单元,字符量占1个单元等,在前面已有详细的介绍.为了正确地访问 ...

  2. 关于delphi Assigned

    1. 根据 Delphi 指令参考手册中 说明: Assigned 函式在参数不为 nil 时传回 True, 表示指针已经指到某个内存地址,这个内存地址可能是一个对象地首地址,也可能在函数或过程中, ...

  3. VS2010/MFC编程入门之一(VS2010与MSDN安装过程图解)

    原文地址: VS2010/MFC编程入门之一(VS2010与MSDN安装过程图解)-软件开发-鸡啄米 http://www.jizhuomi.com/software/139.html   上一讲中鸡 ...

  4. linux用dd测试磁盘速度

    [root@localhost ~]# time dd if=/dev/zero bs=1024 count=1000000 of=/1Gb.file记录了1000000+0 的读入记录了100000 ...

  5. windows和linux共享文件

    一篇文章: 环境:主机操作系统 是Windows XP ,虚拟机 是Ubuntu 9.10,虚拟机是VirtualBox 3.08. 1. 安装增强功能包(Guest Additions) 安装好Ub ...

  6. onlineDDL测试

    onlineDDL语法: alter table ALTER [COLUMN] col_name {SET DEFAULT literal | DROP DEFAULT} ADD [COLUMN] c ...

  7. 24-语言入门-24-cigarettes

    题目地址: http://acm.nyist.edu.cn/JudgeOnline/problem.php?pid=94    描述Tom has many cigarettes. We hypoth ...

  8. 连续多行输入--C++ 中字符串标准输入的学习及实验(续篇)

      编程中常常会用到连续多行输入的情况,如果事先知道要输入多少行的话,可以直接定义一个变量,然后用循环就可以实现了,但有时候事先并不知道,要输入多少行,于是就可以用到输入流碰到文件终止符的情况了,具体 ...

  9. 我的MYSQL学习心得

    我的MYSQL学习心得(一) 简单语法 我的MYSQL学习心得(二) 数据类型宽度 我的MYSQL学习心得(三) 查看字段长度 我的MYSQL学习心得(四) 数据类型 我的MYSQL学习心得(五) 运 ...

  10. 国内顺利使用Google的另类技巧

    在特殊的地方和特殊的时间,流畅顺利使用Google的方法也会变得很特殊.本文不定期保持维护更新,删除不能用的,增加新的网址. 分享一些奇葩的Google使用方法,通过下列网址也可以使用Google来搜 ...