#######solution1#######
# def isPalindrome(x):
# if x<0:
# return False
# else:
# l=str(x)
# newl=l[::-1]
# i=0
# while l[i] is newl[i]:
# if i<len(l)-1:
# i=i+1
# else:
# return True
# return False
######solution2########
# def isPalindrome(x):
# if x<0:
# return False
# else:
# l = str(x)
# for i in range(len(l)//2):
# j=len(l)-i-1
# if l[i] is not l[j]:
# return False
# break
# return True
#####solution 3########
def isPalindrome(x):
if x<0:
return False
y=x
b=0
while x!=0:
b=x%10+10*b
x//=10
if b==y:
return True
return False if __name__=='__main__':
a=121
print(isPalindrome(a))

  第1种和第2种方法都是转换成string,第3种方法效率最高

009_Palindrome Number的更多相关文章

  1. JavaScript Math和Number对象

    目录 1. Math 对象:数学对象,提供对数据的数学计算.如:获取绝对值.向上取整等.无构造函数,无法被初始化,只提供静态属性和方法. 2. Number 对象 :Js中提供数字的对象.包含整数.浮 ...

  2. Harmonic Number(调和级数+欧拉常数)

    题意:求f(n)=1/1+1/2+1/3+1/4-1/n   (1 ≤ n ≤ 108).,精确到10-8    (原题在文末) 知识点:      调和级数(即f(n))至今没有一个完全正确的公式, ...

  3. Java 特定规则排序-LeetCode 179 Largest Number

    Given a list of non negative integers, arrange them such that they form the largest number. For exam ...

  4. Eclipse "Unable to install breakpoint due to missing line number attributes..."

    Eclipse 无法找到 该 断点,原因是编译时,字节码改变了,导致eclipse无法读取对应的行了 1.ANT编译的class Eclipse不认,因为eclipse也会编译class.怎么让它们统 ...

  5. 移除HTML5 input在type="number"时的上下小箭头

    /*移除HTML5 input在type="number"时的上下小箭头*/ input::-webkit-outer-spin-button, input::-webkit-in ...

  6. iOS---The maximum number of apps for free development profiles has been reached.

    真机调试免费App ID出现的问题The maximum number of apps for free development profiles has been reached.免费应用程序调试最 ...

  7. 有理数的稠密性(The rational points are dense on the number axis.)

    每一个实数都能用有理数去逼近到任意精确的程度,这就是有理数的稠密性.The rational points are dense on the number axis.

  8. [LeetCode] Minimum Number of Arrows to Burst Balloons 最少数量的箭引爆气球

    There are a number of spherical balloons spread in two-dimensional space. For each balloon, provided ...

  9. [LeetCode] Number of Boomerangs 回旋镖的数量

    Given n points in the plane that are all pairwise distinct, a "boomerang" is a tuple of po ...

随机推荐

  1. gulp配置(编译压缩转码自动刷新注释全)

    参考自:http://www.sheyilin.com/2016/02/gulp_introduce/ 在原先基础上增加了less编译 es6转码资源地图等,修改了一部分的热刷新. gulpfile. ...

  2. python之常用模块

    python 常用模块 之 (subprocess模块.logging模块.re模块) python 常用模块 之 (序列化模块.XML模块.configparse模块.hashlib模块) pyth ...

  3. zabbix,php,nginx,mysql源码安装 神仙操作

    →软件包 mkdir /soft/ cd /soft ♦下载以下软件包 nginx-1.14.2.tar.gz wget http://nginx.org/download/nginx-1.14.2. ...

  4. MAX

    Max的用法1(Min类似) Matlab中max函数在矩阵中求函数大小的实例如下: C = max(A)返回一个数组各不同维中的最大元素.如果A是一个向量,max(A)返回A中的最大元素.如果A是一 ...

  5. Autoware(2)—加载地图数据

    选择Point cloud.Ref选择.autoware/.data/map/pointcloud_map/里面的全选 点Point cloud加载 vector Map和TF同理

  6. [Oracle运维工程师手记] 如何从trace 文件,判断是否执行了并行

    [Oracle运维工程师手记系列]如何从trace 文件,判断是否执行了并行 客户说,明明指定了并行的hint,OEM 却报说没有并行,并且提供了画面. 客户的SQL文长这样: INSERT/*+ p ...

  7. Java Mail 实现第三方邮件发送功能

    1 创建一个用于发送邮件的类 package com.latiny.service; import java.io.IOException; import java.io.InputStream; i ...

  8. python常用的基本操作

    打开cmd,pip list 可以查看python安装的所以第三方包

  9. Linux下C语言生成可执行文件的过程

    在当前目录下创建一个C源文件并打开: touch test.c gedit test.c直接编译: gcc test.c -o test 分步骤编译: 1) 预处理    gcc -E test.c  ...

  10. Kubernetes 中的渐进式交付:蓝绿部署和金丝雀部署

    渐进式交付是持续交付的下一步, 它将新版本部署到用户的一个子集,并在将其滚动到全部用户之前对其正确性和性能进行评估, 如果不匹配某些关键指标,则进行回滚. 这里有一些有趣的项目,使得渐进式交付在 Ku ...