[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 ...
随机推荐
- delphi ICS控件示例解读
{* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * Author: Fran鏾is PIETTE ...
- Java图形化界面设计——中间容器(Jpanel)
1. 将组件添加到JFrame中 方式之一: frame.getContentPane().add(childComponent) 用getContentPane()方法获得JFrame的内容面板, ...
- html网页编码问题
之前碰到过一些html编码乱码问题,都理解的模模糊糊,问了别人解释的也是模模糊糊.近期要做前端这个问题研究了下仅仅须要两句话就能非常清楚的解释了(之前问的那些人是不是自己都没理解非常郁闷.) < ...
- button 变成圆
btn.layer.cornerRdius = width/2.0;btn.layer.maskToBounds = width/2.0:
- slots
class Student(object): pass s = Student() s.name = 'Michael' print(s.name) def set_age(self, age): s ...
- php学习笔记(3)
1.计数器 <?php /* simple access counter for php3 (c)1998 David W. Bettis dbettis@eyeintegrated.com m ...
- C——货物管理系统
#include <stdio.h> #include <stdlib.h> #include <string.h> #include <conio.h> ...
- (C#)Windows Shell 外壳编程系列6 - 执行
原文(C#)Windows Shell 外壳编程系列6 - 执行 (本系列文章由柠檬的(lc_mtt)原创,转载请注明出处,谢谢-) 接上一节:(C#)Windows Shell 外壳编程系列5 - ...
- 盘点:移动服务 #AzureChat
感谢大家帮助我们顺利推出史无前例的 #AzureChat.移动服务和 Notification Hub 是 Windows Azure 平台上令人振奋的服务.我们很高兴能借这次在线讨论的机会,倾听各位 ...
- APUE学习之---------------进程
离职了,交接期也有足够的时间了,可以在好好的再看一下APUE,想想上次详细的看还是在两年之前,虽然中间也偶尔会翻出来看看,但是由于工作上交集相对比较少一直没有去细读一下.现在正好是一段空挡期可以好好看 ...