[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 ...
 
随机推荐
- c++ 静态多态与动态多态
			
多态polymorphism是指具有多种形态的情况,它能根据单一的标记关联不同的行为.多态是面向对象程序设计的基础.在面向对象程序设计中的多态是一种运行时的多态.C++中有两种多态,称为动多态(运行时 ...
 - Android利用tcpdump和wireshark抓取网络数据包
			
Android利用tcpdump和wireshark抓取网络数据包 主要介绍如何利用tcpdump抓取andorid手机上网络数据请求,利用Wireshark可以清晰的查看到网络请求的各个过程包括三次 ...
 - Socket编程指南及示例程序
			
例子代码就在我的博客中,包括六个UDP和TCP发送接受的cpp文件,一个基于MFC的局域网聊天小工具工程,和此小工具的所有运行时库.资源和执行程序.代码的压缩包位置是http://www.blogja ...
 - InitParam与ContextParm的异同
			
web.xml里面可以定义两种参数:(1)application范围内的参数,存放在servletcontext中,在web.xml中配置如下: xml 代码 <context-param> ...
 - Oracle fga审计有这几个特性
			
fga审计有这几个特性: 本文为原创文章,转载请注明出处: http://blog.csdn.net/msdnchina/article/details/38409057 1.select * fro ...
 - IOS框架概览
			
iOS是执行在iPhone.iPod Touch或iPad上的操作系统,之前叫做iPhone OS,iOS与Mac OS X有共同的基础架构和底层技术.但iOS是依据移动设备的特点而设计的,所以和Ma ...
 - 在windows下完美安装GitHub
			
笔者最近在Windows下安装GitHub,过程中遇到不少问题.现在把安装的详细步骤分享给大家,免得大家走弯路. 笔者安装了GitHub for Windows程序,一切都运行顺利.但事情没有结束,首 ...
 - Robolectric 探索之路
			
layout: post title: Roboletric探索之路,从抗拒到依赖 description: Roboletric Android Unit Testing category: blo ...
 - iOS开发之AsyncSocket使用教程
			
用socket可以实现像QQ那样发送即时消息的功能.客户端和服务端需要建立长连接,在长连接的情况下,发送消息.客户端可以发送心跳包来检测长连接. 在iOS开发中使用socket,一般都是用第三方库As ...
 - DataSet中取值(转)
			
1 DataSet.Table[0].Rows[ i ][ j ] 其中i 代表第 i 行数, j 代表第 j 列数 2 DataSet.Table[0].Rows[ i ].ItemArray[ j ...