LeetCode 9. Palindrome Number (回文数字)
Determine whether an integer is a palindrome. Do this without extra space.
题目标签:Math
题目给了我们一个int x, 让我们判断它是不是回文数字。
首先,负数就不是回文数字,因为有个负号。
剩下的都是正数,只要把数字 reverse 一下,和原来的比较,一样就是回文。
当有overflow 的时候,返回一个负数就可以了(因为负数肯定不会和正数相等)。
Java Solution:
Runtime beats 61.47%
完成日期:06/12/2017
关键词:Palindrome
关键点:reverse number
class Solution
{
public boolean isPalindrome(int x)
{
if(x < 0)
return false; int pd = reverse(x); return x == pd ? true : false;
} public int reverse(int num)
{
int res = 0; while(num != 0)
{
int tail = num % 10;
int newRes = res * 10 + tail; if((newRes - tail) / 10 != res) // check overflow
return -1; // -1 will not equal to positive number res = newRes;
num = num / 10;
} return res;
}
}
参考资料:N/A
LeetCode 题目列表 - LeetCode Questions List
题目来源:https://leetcode.com/
LeetCode 9. Palindrome Number (回文数字)的更多相关文章
- 【LeetCode每天一题】Palindrome Number( 回文数字)
Determine whether an integer is a palindrome. An integer is a palindrome when it reads the same back ...
- leetcode 9 Palindrome Number 回文数
Determine whether an integer is a palindrome. Do this without extra space. click to show spoilers. S ...
- [LeetCode]9. Palindrome Number回文数
Determine whether an integer is a palindrome. An integer is a palindrome when it reads the same back ...
- 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】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 ...
- [LeetCode] Valid Palindrome 验证回文字符串
Given a string, determine if it is a palindrome, considering only alphanumeric characters and ignori ...
- LeetCode Valid Palindrome 有效回文(字符串)
class Solution { public: bool isPalindrome(string s) { if(s=="") return true; ) return tru ...
- 9. Palindrome Number 回文 my second leetcode 20170807
Determine whether an integer is a palindrome. Do this without extra space. click to show spoilers. S ...
随机推荐
- 关于WIN7开始“搜索程序和文件”
大家好,我是WIN7使用者.关于WIN7开始>搜索程序和文件,这点功能强大,但是本人电脑水平不好,几乎不怎么会用. 我知道可以找出相应的软件,但是我想知道的是,可以找出电脑相应的功能,到某个界面 ...
- GPC:使用GPC计算intersection容易出现的问题
在使用GPC计算多边形的交的时候,出现问题 //1.2. 另一种方法,判断新的多边形是否和老多边形相交 Poly cross = (PolyDefault) Clip.intersection ...
- [转]最值得拥有的免费Bootstrap后台管理模板
在PHP开发项目中,后台管理因为面向群体相对比较固定,大部分以实现业务逻辑和功能.使用Bootstrap后台模板可以让后端开发很轻松的就展现给客户一个响应式的后台,节约前端开发的时间.下面PHP程序员 ...
- Mybatis学习总结一
一.Mybatis架构 JAR包下载地址 1. mybatis配置 SqlMapConfig.xml,此文件作为mybatis的全局配置文件,配置了mybatis的运行环境等信息. mapper. ...
- react antD 日期选择
<DatePicker disabledDate={disabledDate} onChange={this.onChange} /> //创建时间禁用大于当前时间 <moment( ...
- 常用的HTTP测试工具谷歌浏览器插件汇总
网页的开发和测试时最常见的测试就是HTTP测试,作为曾经的测试人员在这方面还是略知一二的.其实做网页测试工作是非常繁琐的时期,有时候甚至是无聊重复的,如果没有网页测试工具的帮助的话,测试人员会越做越怀 ...
- 1.ARM嵌入式体系结构与接口技术(Cortex-A8版)
第1章 嵌入式系统基础知识 ---->1.1嵌入式系统的概述 -------->1.1.1嵌入式系统简介 -------->1.1.2嵌入式系统的特点 -------->1.1 ...
- Just a Hook (HDU 1698) 懒惰标记
Just a Hook (HDU 1698) 题链 每一次都将一个区间整体进行修改,需要用到懒惰标记,懒惰标记的核心在于在查询前才更新,比如将当前点rt标记为col[rt],那么此点的左孩子和右孩子标 ...
- F - Shooter
UVA___10535 The shooter is in a great problem. He is trapped in a “2D” maze with a laser gun and can ...
- visioStudio常见问题
问题一: 在做项目时候,使用VisioStudio 2008,一不小心将设置恢复到了原始,一直找不到需要的东西. 比如生成方式“debug”和“Release”选择框没有.一些图标也没有. 经过不断的 ...