[LeetCode]9. Palindrome Number回文数
Determine whether an integer is a palindrome. An integer is a palindrome when it reads the same backward as forward.
Example 1:
Input: 121
Output: true
Example 2:
Input: -121
Output: false
Explanation: From left to right, it reads -121. From right to left, it becomes 121-. Therefore it is not a palindrome.
Example 3:
Input: 10
Output: false
Explanation: Reads 01 from right to left. Therefore it is not a palindrome.
Follow up:
Coud you solve it without converting the integer to a string?
还是回文的问题,这题没有给出数字的区间,不过我们不用担心,回文数正反一样所以反过来也不会溢出的,我们可以利用之前的整数翻转的方法,如果回文reverse之后肯定相等
另外根据题意负数肯定是不回文的
class Solution {
    public boolean isPalindrome(int x) {
        if(x<0) return false;
        if(x!=reverse(x)) return false;
        return true;
    }
    public int reverse(int x) {
        int res = 0,tag=0;
        while (x != 0) {
            tag = res * 10 + x % 10;
            if (tag / 10 != res) return 0;
            res = tag;
            x = x / 10;
        }
        return res;
    }
}
[LeetCode]9. Palindrome Number回文数的更多相关文章
- leetcode 9 Palindrome Number 回文数
		Determine whether an integer is a palindrome. Do this without extra space. click to show spoilers. S ... 
- Leetcode 3——Palindrome Number(回文数)
		Problem: Determine whether an integer is a palindrome. Do this without extra space. 简单的回文数,大一肯定有要求写过 ... 
- 【LeetCode】Palindrome Number(回文数)
		这道题是LeetCode里的第9道题. 题目说的: 判断一个整数是否是回文数.回文数是指正序(从左向右)和倒序(从右向左)读都是一样的整数. 示例 1: 输入: 121 输出: true 示例 2: ... 
- LeetCode Problem 9:Palindrome Number回文数
		描述:Determine whether an integer is a palindrome. Do this without extra space. Some hints: Could nega ... 
- 【LeetCode】9. Palindrome Number 回文数
		作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 公众号:负雪明烛 本文关键词:回文数,回文,题解,Leetcode, 力扣,Python ... 
- [LeetCode] Prime Palindrome 质数回文数
		Find the smallest prime palindrome greater than or equal to N. Recall that a number is prime if it's ... 
- Palindrome Number 回文数
		判断一个数字是否是回文数,尝试不用其他额外空间. 注意: 负数也有可能成为回文数吗? 如果你想让int转为string,注意不用其他空间这个约束. 你也可以翻转一个int,但是有可能会溢出. ... 
- 【LeetCode】9 Palindrome Number 回文数判定
		题目: Determine whether an integer is a palindrome. Do this without extra space. Some hints: Could neg ... 
- 9. Palindrome Number 回文数的判断
		[抄题]: Determine whether an integer is a palindrome. An integer is a palindrome when it reads the sam ... 
随机推荐
- 报错:Caused by: org.hibernate.id.IdentifierGenerationException: ids for this class must be manually assigned before calling save(): cn.itcast.bos.domain.base.SubArea
			因为 实体类中的主键 是String类型 不能自动为其分配id 所以需要手动设置在service层 model.setId(UUID.randomUUID().toString()); 
- redis  有用 Sorted-Set 应用场景
			1.1.1Set数据类型的 使用场景 1.可以使用Redis的Set数据类型跟踪一些唯一性数据,比如访问某一博客的唯一IP地址信息.对于此场景,我们仅需在每次访问该博客时将访问者的IP存入Redis中 ... 
- 第 2 章	Python 语言入⻔
			目录 2.1低而长的学习曲线 2.2Python的优势 2.3在你的计算机中安装Python 2.4如何运行Python程序 2.5文本编辑器 2.6寻求帮助 Python语言是一种流行的编程语言,在 ... 
- 理解setTimeout和setInterval
			setTimeout和setInterval,这两个js函数都是用来定时执行.setTimeout执行一次,setInterval执行多次. 问题出现在今天,使用setInterval是,设置执行速度 ... 
- 第一章 –– Java基础语法
			第一章 –– Java基础语法 span::selection, .CodeMirror-line > span > span::selection { background: #d7d4 ... 
- 「CF744C」Hongcow Buys a Deck of Cards「状压 DP」
			题意 你有\(n\)个物品,物品和硬币有\(A\),\(B\)两种类型,假设你有\(M\)个\(A\)物品和\(N\)个\(B\)物品 每一轮你可以选择获得\(A, B\)硬币各\(1\)个,或者(硬 ... 
- laravel 导出插件
			转发:https://blog.csdn.net/gu_wen_jie/article/details/79296470 版本:laravel5 php 5.6 安装步骤: 一.安装插件 ①.首先在L ... 
- flask-sqlalchemy中 backref lazy的参数实例解释和选择
			官方文档:http://docs.sqlalchemy.org/en/rel_1_0/orm/basic_relationships.html#relationship-patterns 最近在学习到 ... 
- Solr 6.7学习笔记(02)--  配置文件 managed-schema (schema.xml)(1)
			刚学Solr(版本6.7.0),新建一个core时,提示要求schema.xml文件,我找了半天也没在源码包中找到名为schema.xml的文件.这个版本其实用的是managed-schema文件,没 ... 
- input 上传文件的判断
			<html> <head> <meta charset='utf-8'> <meta name="viewport" content=&q ... 
