#######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. DRF 序列化器-Serializer (2)

    作用 1. 序列化,序列化器会把模型对象转换成字典,经过response以后变成json字符串 2. 完成数据校验功能 3. 反序列化,把客户端发送过来的数据,经过request以后变成字典,序列化器 ...

  2. .net core iis配置

    微软官方教程: https://docs.microsoft.com/en-us/aspnet/core/publishing/iis?tabs=aspnetcore2x 在vs中创建.net cor ...

  3. ORM相关操作

    1.一般操作 <1> all(): 查询所有结果 <2> filter(**kwargs): 它包含了与所给筛选条件相匹配的对象 <3> get(**kwargs) ...

  4. python小白——进阶之路——day2天-———容器类型数据(list,set ,tuple,dict,str)

    #容器类型数据 : list tuple # ###列表的特性:可获取,可修改,有序 # 声明一个空列表 listvar = [] print(listvar,type(listvar)) # (1) ...

  5. firewall centos

    firewall-cmd --add-port=8056/tcp    --临时增加端口 firewall-cmd --permanent --zone=public --add-port=6069/ ...

  6. 使用maven时出现Failure to transfer 错误的解决方法

    在eclipse里使用maven,连接nexus私服. 添加依赖之后,总是报添加的依赖jar文件找不到,但是在nexus的库里面能找到这个依赖的jar文件,但是在本地的maven库里面找不到,于是我将 ...

  7. Docker启动的问题解决笔记

    一.错误信息1:解决VM 与 Device/Credential Guard 不兼容  错误原因: 1.出现此问题的原因是Device Guard或Credential Guard与Workstati ...

  8. 不要再被骗了------QQ盗号原理大揭秘

    前言 相信大家在懵懂无知的时候都有被盗号的经历吧,QQ胡乱的加好友,突然有个好友传了个文件给你,打开以后发现QQ竟然显示强制下线,然后再也上不去了QAQ,很明显,QQ号被人盗了.最近也是很多小伙伴私信 ...

  9. H5调用手机拍照并展示在前端页面

    <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...

  10. SpringMVC返回json数据的三种方式(转)

    原文:https://blog.csdn.net/shan9liang/article/details/42181345# 1.第一种方式是spring2时代的产物,也就是每个json视图contro ...