当前位置:网站首页>leetcode-2. Palindrome judgment
leetcode-2. Palindrome judgment
2022-07-06 01:38:00 【East invincible is me】
Give you an integer x , If x Is a palindrome integer , return true ; otherwise , return false .
Palindrome number refers to positive order ( From left to right ) Reverse order ( From right to left ) Read all the same integers .
for example ,121 It's palindrome. , and 123 No .
My original idea of this question is based on java Of , Turn a string into an array , Then cut it in half and compare it before and after , use python It's really troublesome to write . Look at the ideas given in the solution
class Solution:
def isPalindrome(self, x: int):
return (str(x)[::-1]==str(x))
take int To str, Flip the string by slicing , Then compare with the original string . It's a very simple way .
# Method 2 reversed function
#print("".join(reversed(a))==a)
#print(''.join(reversed(a))) reversed(a) What you get is a list join List get string
#. join(): Connection string array . The string 、 Tuples 、 Elements in the list with the specified characters ( Separator ) The connection generates a new string
Use reversed function , Flip the string , And then through join Method , Convert the list to a string , Another comparison .
边栏推荐
- Docker compose配置MySQL并实现远程连接
- Leetcode 208. Implement trie (prefix tree)
- Mathematical modeling learning from scratch (2): Tools
- [network attack and defense training exercises]
- Cookie concept, basic use, principle, details and Chinese transmission
- National intangible cultural heritage inheritor HD Wang's shadow digital collection of "Four Beauties" made an amazing debut!
- [Jiudu OJ 09] two points to find student information
- 记一个 @nestjs/typeorm^8.1.4 版本不能获取.env选项问题
- Mongodb problem set
- A Cooperative Approach to Particle Swarm Optimization
猜你喜欢
Electrical data | IEEE118 (including wind and solar energy)
About error 2003 (HY000): can't connect to MySQL server on 'localhost' (10061)
【Flask】官方教程(Tutorial)-part3:blog蓝图、项目可安装化
NiO related knowledge (II)
一圖看懂!為什麼學校教了你Coding但還是不會的原因...
Idea sets the default line break for global newly created files
[flask] official tutorial -part2: Blueprint - view, template, static file
国家级非遗传承人高清旺《四大美人》皮影数字藏品惊艳亮相!
黄金价格走势k线图如何看?
TrueType字体文件提取关键信息
随机推荐
Redis-列表
Force buckle 9 palindromes
3D model format summary
Accelerating spark data access with alluxio in kubernetes
Ordinary people end up in Global trade, and a new round of structural opportunities emerge
TrueType字体文件提取关键信息
Threedposetracker project resolution
c#网页打开winform exe
【Flask】官方教程(Tutorial)-part1:项目布局、应用程序设置、定义和访问数据库
C web page open WinForm exe
【网络攻防实训习题】
现货白银的一般操作方法
ClickOnce does not support request execution level 'requireAdministrator'
Docker compose configures MySQL and realizes remote connection
Unity | two ways to realize facial drive
Alibaba canal usage details (pit draining version)_ MySQL and ES data synchronization
Basic operations of databases and tables ----- default constraints
Flutter Doctor:Xcode 安装不完整
Leetcode 208. Implement trie (prefix tree)
What is weak reference? What are the weak reference data types in ES6? What are weak references in JS?