Determine whether an integer is a palindrome. Do this without extra space.

判断一个整数是否是回文数。

思路:求出数字abcd的逆序的数值dcba,如果是回文数的话,那么abcd==dcba。

时间复杂度:O(n)

python代码:

 class Solution(object):
def isPalindrome(self, x):
"""
:type x: int
:rtype: bool
"""
temp = x
revert_x = 0
while temp > 0:
revert_x = revert_x*10 + temp % 10
temp //= 10
return revert_x == x

LeetCode-9-Palindrome Number的更多相关文章

  1. Leetcode练习题 Palindrome Number

    9. Palindrome Number Question: Determine whether an integer is a palindrome. An integer is a palindr ...

  2. Leetcode 9. Palindrome Number(水)

    9. Palindrome Number Easy Determine whether an integer is a palindrome. An integer is a palindrome w ...

  3. leetcode 9 Palindrome Number 回文数

    Determine whether an integer is a palindrome. Do this without extra space. click to show spoilers. S ...

  4. LeetCode 9. Palindrome Number (回文数字)

    Determine whether an integer is a palindrome. Do this without extra space. 题目标签:Math 题目给了我们一个int x, ...

  5. Leetcode 9. Palindrome Number(判断回文数字)

    Determine whether an integer is a palindrome. Do this without extra space.(不要使用额外的空间) Some hints: Co ...

  6. [LeetCode][Python]Palindrome Number

    # -*- coding: utf8 -*-'''__author__ = 'dabay.wang@gmail.com'https://oj.leetcode.com/problems/palindr ...

  7. 蜗牛慢慢爬 LeetCode 9. Palindrome Number [Difficulty: Easy]

    题目 Determine whether an integer is a palindrome. Do this without extra space. Some hints: Could nega ...

  8. [LeetCode] 9.Palindrome Number - Swift

    Determine whether an integer is a palindrome. Do this without extra space. 题目意思:判断一个整数是否是回文数 例如:1232 ...

  9. [LeetCode] 9. Palindrome Number 验证回文数字

    Determine whether an integer is a palindrome. An integer is a palindrome when it reads the same back ...

  10. 【leetcode】Palindrome Number

    题目简述: Determine whether an integer is a palindrome. Do this without extra space. Some hints: Could n ...

随机推荐

  1. jQuery带tab切换搜索框样式代码

    效果体验:http://hovertree.com/texiao/jquery/23/ 代码如下,保存到HTML文件也可以查看效果: <!DOCTYPE html> <html la ...

  2. ButterKnife基本使用

    ButterKnife基本使用 Butter Knife处理字段和方法绑定.   重要更新: 目前(2016.4.29), ButterKnife的最新版本是8.0.1. Demo项目已更新: htt ...

  3. 谈谈iOS中的锁

    1 前言 近日工作不是太忙,刚好有时间了解一些其他东西,本来打算今天上午去体检,但是看看天气还是明天再去吧,也有很大一个原因:就是周六没有预约上!闲话少说,这里简单对锁来个简单介绍分享. 2 目录 第 ...

  4. [转]完美洗牌(Perfect Shuffle)问题

    [转]原博文地址:https://github.com/julycoding/The-Art-Of-Programming-By-July/blob/master/ebook/zh/02.09.md ...

  5. Linux命令学习总结:cd命令

    命令简介: 该命令用来切换当前目录.cd 是change directory 的缩写 命令语法: cd [-L|-P] [dir] 使用示例 1:切换到当前目录的上一级目录 1: [root@DB-S ...

  6. jQuery标签选择器

    $(function() { //alert("hello jquery"); //选择器 //id选择器 $("#bt1").click( function( ...

  7. android开发之onCreate( )方法详解

    这里我们只关注一句话:This is where you should do all of your normal static set up.其中我们只关注normal static,normal: ...

  8. nginx 配置php

    安装php yum install php   yum install php-mysql php-gd php-imap php-ldap php-odbc php-pear php-xml php ...

  9. Tomcat关闭日志catalina.out

    catalina.out文件会越来越大,对系统的稳定造成了一定的影响.conf/logging.properties 一般在部署Tomcat后,运行久了,catalina.out文件会越来越大,对系统 ...

  10. Centos6.5下设置静态IP

    1.编辑网卡配置文件 vi /etc/sysconfig/network-scripts/ifcfg-eth0 设置网卡eth0的IPV4信息,需要注意的是,设置的IPADDR需要和局域网中其他机器处 ...