009_Palindrome Number
#######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的更多相关文章
- JavaScript Math和Number对象
目录 1. Math 对象:数学对象,提供对数据的数学计算.如:获取绝对值.向上取整等.无构造函数,无法被初始化,只提供静态属性和方法. 2. Number 对象 :Js中提供数字的对象.包含整数.浮 ...
- Harmonic Number(调和级数+欧拉常数)
题意:求f(n)=1/1+1/2+1/3+1/4-1/n (1 ≤ n ≤ 108).,精确到10-8 (原题在文末) 知识点: 调和级数(即f(n))至今没有一个完全正确的公式, ...
- Java 特定规则排序-LeetCode 179 Largest Number
Given a list of non negative integers, arrange them such that they form the largest number. For exam ...
- Eclipse "Unable to install breakpoint due to missing line number attributes..."
Eclipse 无法找到 该 断点,原因是编译时,字节码改变了,导致eclipse无法读取对应的行了 1.ANT编译的class Eclipse不认,因为eclipse也会编译class.怎么让它们统 ...
- 移除HTML5 input在type="number"时的上下小箭头
/*移除HTML5 input在type="number"时的上下小箭头*/ input::-webkit-outer-spin-button, input::-webkit-in ...
- 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.免费应用程序调试最 ...
- 有理数的稠密性(The rational points are dense on the number axis.)
每一个实数都能用有理数去逼近到任意精确的程度,这就是有理数的稠密性.The rational points are dense on the number axis.
- [LeetCode] Minimum Number of Arrows to Burst Balloons 最少数量的箭引爆气球
There are a number of spherical balloons spread in two-dimensional space. For each balloon, provided ...
- [LeetCode] Number of Boomerangs 回旋镖的数量
Given n points in the plane that are all pairwise distinct, a "boomerang" is a tuple of po ...
随机推荐
- SQL 约束 (Constraints)
SQL 约束 约束用于限制加入表的数据的类型. 可以在创建表时规定约束(通过 CREATE TABLE 语句),或者在表创建之后也可以(通过 ALTER TABLE 语句). 我们将主要探讨以下几种约 ...
- Netstat 常用命令--备忘录
Netstat 用于显示与IP .TCP .UDP 和ICMP 协议相关的统计数据,一般用于检验本机各端口的网络连接情况. 常用参数 -a (all)显示所有选项,默认不显示LISTEN相关-t (t ...
- AI Conditional GAN
Conditional GAN 参考链接: https://arxiv.org/pdf/1611.07004v1.pdf
- gulp 自动ftp至服务器时,处理开发 测试服务器地址问题
var gulp=require('gulp'), babel = require('gulp-babel'), gulpSequence = require('gulp-sequence'), ht ...
- 如何在已有的 Web 应用中使用 ReactJS
原文:How to Sprinkle ReactJS into an Existing Web Application 译者:nzbin 当我们学习一项新技术,可能是一个 JavaScript 框架, ...
- Python--day01(计算机基础)
Python: python 是一门面向后台的编程语言,在大数据,数据分析,机器学习,人工智能,爬虫,自动化运维,web等方面具有强大功能. 基础阶段学习内容:基本语法,文件处理,函数,模块,面向对象 ...
- python 通过 http、dns、icmp判断网络状态
#http使用requests发包bs4解析,dns.icmp 使用scapy发包import time import threading import requests,bs4 from scapy ...
- final和static关键字
1.如果类只有静态方法,可以将构造函数标记为private以避免被初始化: 2.常量同时标记为static和final,常量名全部大写,下划线连接: 3.final修饰一个成员变量(属性),必须要显示 ...
- 安装VM-tools
win10系统 VMware12 Ubuntu64位安装VM-tools时所遇到的提示信息: open-vm-tools are available from the OS vendor and VM ...
- Java的selenium代码随笔(1)
package ShareClass; import java.awt.AWTException;import java.awt.Robot;import java.awt.Toolkit;impor ...