题目

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

解法

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

代码

 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. SaaS系列介绍之十三: SaaS系统体系架构

    1 系统体系架构设计 软件开发中系统体系架构决定了一个系统稳定性.健壮性.可扩展性.兼容性和可用性,它是系统的灵魂.体系架构是架构师所关注的核心.良好的体系架构是系统成功的开端,否则,再好的代码与设计 ...

  2. 随机森林分类(Random Forest Classification)

    其实,之前就接触过随机森林,但仅仅是用来做分类和回归.最近,因为要实现一个idea,想到用随机森林做ensemble learning才具体的来看其理论知识.随机森林主要是用到决策树的理论,也就是用决 ...

  3. 机器学习第三课(EM算法和高斯混合模型)

    极大似然估计,只是一种概率论在统计学的应用,它是参数估计的方法之一.说的是已知某个随机样本满足某种概率分布,但是其中具体的参数不清楚,参数估计就是通过若干次试验,观察其结果,利用结果推出参数的大概值. ...

  4. 【nginx运维基础(6)】Nginx的Rewrite语法详解

    概述 重写URL是非常有用的一个功能,因为它可以让你提高搜索引擎阅读和索引你的网站的能力:而且在你改变了自己的网站结构后,无需要求用户修改他们的书签,无需其他网站修改它们的友情链接:它还可以提高你的网 ...

  5. JavaScript中样式,方法 函数的应用

    JavaScript中一个字母都不能错,编写的时候他不报错,也不提示,只有在执行的时候才会提示错误位置 . 一.样式 .waring {background-color:yellow } .highl ...

  6. 持久化框架Hibernate 开发实例(二)

    1 简述 通过使用Hibernate框架,开发者可以使用面向对象的方式来进行数据库访问,从而取代 以前使用JDBC进行数据库访问的方式.通过使用Hibernate框架,web应用可以通过面向 对象的方 ...

  7. Tomcat 管理页面

    一.配置刚下载的解压版的apache-tomcat,启动后,通过浏览器访问:http://127.0.0.1:8080/(或者http://localhost:8080)然后点击下图的Server s ...

  8. android Json 使用

    http://www.cnblogs.com/mybkn/archive/2012/05/18/2508306.html http://www.cnblogs.com/haippy/archive/2 ...

  9. !!流行的php面试题及答案

    分类: 1.在PHP中,当前脚本的名称(不包括路径和查询字符串)记录在预定义变量(1)中:而链接到当前页面的URL记录在预定义变量(2)中. 答:echo $_SERVER['PHP_SELF']; ...

  10. jsp中四种传递参数的方法

    jsp中四种传递参数的方法如下: 1.form表单 2.request.setAttribute();和request.getAttribute(); 3.超链接:<a herf="i ...