[LeetCode]题解(python):009-Palindrome Number
题目来源:
https://leetcode.com/problems/palindrome-number/
题意分析:
这题是要判断一个int是否一个回文数,要求不能申请额外的空间。
题目思路:
这题也是一个简单的题目,由于不能申请额外的空间,所以不能将int转换成string来处理。根据回文数的定义,我们可以考虑将一个int翻转过来,翻转的时候要注意不能超过32位int的最大值。
代码(python):
class Solution(object):
def isPalindrome(self, x):
"""
:type x: int
:rtype: bool
"""
if x < 0:
return False
b = x
ans = 0
while x > 0:
ans = ans*10 + x%10
if x > 2147483647:
return False
x //= 10
if ans == b:
return True
return False
转载请注明出处:http://www.cnblogs.com/chruny/p/4801704.html
[LeetCode]题解(python):009-Palindrome Number的更多相关文章
- No.009 Palindrome Number
9. Palindrome Number Total Accepted: 136330 Total Submissions: 418995 Difficulty: Easy Determine whe ...
- LeetCode--No.009 Palindrome Number
9. Palindrome Number Total Accepted: 136330 Total Submissions: 418995 Difficulty: Easy Determine whe ...
- Leetcode 题目整理-3 Palindrome Number & Roman to Integer
9. Palindrome Number Determine whether an integer is a palindrome. Do this without extra space. clic ...
- leetCode练题——9. Palindrome Number
1.题目 9. Palindrome Number Determine whether an integer is a palindrome. An integer is a palindrome ...
- 【LeetCode】009. Palindrome Number
Determine whether an integer is a palindrome. Do this without extra space. Some hints: Could negativ ...
- 【JAVA、C++】LeetCode 009 Palindrome Number
Determine whether an integer is a palindrome. Do this without extra space. 解题思路一: 双指针法,逐位判断 Java代码如下 ...
- [Leetcode]009.Palindrome Number
public class Solution { public boolean isPalindrome(int x) { if (x<0 || (x!=0 && x%10==0) ...
- 【LeetCode算法-9】Palindrome Number
LeetCode第9题 Determine whether an integer is a palindrome. An integer is a palindrome when it reads t ...
- LeetCode记录之9——Palindrome Number
LeetCode真是个好东西,本来闲了一下午不想看书,感觉太荒废时间了就来刷一道题.能力有限,先把easy的题目给刷完. Determine whether an integer is a palin ...
- 【LeetCode】9、Palindrome Number(回文数)
题目等级:Easy 题目描述: Determine whether an integer is a palindrome. An integer is a palindrome when it rea ...
随机推荐
- bootstrap 更改container 的width
参考:http://stackoverflow.com/questions/15884102/bootstrap-how-do-i-change-the-width-of-the-container ...
- data pump(数据泵)
先给出oracle给出的一个定义: “Oracle Data Pump technology enables very high-speed movement of data and metadata ...
- iso-开发基础知识-5-适配器
个人学习总结仅供参考:欢迎拍砖 1.适配器:用于连接两种不同种类的对象. 2.分为2种:类适配,对象适配. 3.委托(Delegate)模式属于对象适配器: 4.何时使用适配器模式 书中的这幅图更好的 ...
- javascript中对变量类型的推断
本文正式地址:http://www.xiabingbao.com/javascript/2015/07/04/javascript-type 在JavaScript中,有5种基本数据类型和1种复杂数据 ...
- HEVC与VP9编码效率对比
HEVC(High EfficiencyVideo Coding,高效率视频编码)是一种视频压缩标准,H.264/MPEG-4 AVC的继任者.目前正在由ISO/IEC MPEG和ITU-T VCEG ...
- Android视频应用去广告学习实践
注意:本文仅仅供学习研究用途 第一步 素材搜集 腾讯视频应用:http://download.csdn.net/detail/itleaks/7991795 反汇编工具: ...
- TCP各种连接状态注释
TCP各种连接状态注释 连接进程是通过一系列状态表示的,这些状态有:LISTEN,SYN-SENT,SYN-RECEIVED,ESTABLISHED,FIN-WAIT-1,FIN-WAIT-2,CL ...
- 练习笔记:net,JqueryUI实现自动补全功能
1.首先建立个空的Web项目 2.将下载好的JqueryUI文件保存到JS文件加下 3.引入JS文件 <link href="JS/css/ui-lightness/jquery-ui ...
- window.showModalDialog刷新父窗口和本窗口的方法及注意
window.showModalDialog刷新父窗口和本窗口的方法及注意: 一.刷新父窗口的方法: A.使用window.returnValue给父窗口传值,然后根据值判断是否刷新. 在w ...
- Javascript 递归函数
递归函数就是在函数内部调用它自己.在Javascript 中有很多写法,值得我们学习一下(Javascript太灵活了).还是用n的 阶乘 来写例子吧. 1. 首先,来看一个最普通 最正常的写法. f ...