当前位置:网站首页>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 .
边栏推荐
- How does Huawei enable debug and how to make an image port
- Maya hollowed out modeling
- NiO related knowledge (II)
- Leetcode sword finger offer 59 - ii Maximum value of queue
- Tcpdump: monitor network traffic
- 什么是弱引用?es6中有哪些弱引用数据类型?js中的弱引用是什么?
- Kubernetes stateless application expansion and contraction capacity
- [understanding of opportunity-39]: Guiguzi - Chapter 5 flying clamp - warning 2: there are six types of praise. Be careful to enjoy praise as fish enjoy bait.
- Mongodb problem set
- selenium 等待方式
猜你喜欢
3D模型格式汇总
MATLB|实时机会约束决策及其在电力系统中的应用
MUX VLAN configuration
[detailed] several ways to quickly realize object mapping
Redis-列表
How to upgrade kubernetes in place
Alibaba canal usage details (pit draining version)_ MySQL and ES data synchronization
【SSRF-01】服务器端请求伪造漏洞原理及利用实例
【Flask】官方教程(Tutorial)-part1:项目布局、应用程序设置、定义和访问数据库
UE4 unreal engine, editor basic application, usage skills (IV)
随机推荐
【SSRF-01】服务器端请求伪造漏洞原理及利用实例
NiO related knowledge (II)
[机缘参悟-39]:鬼谷子-第五飞箝篇 - 警示之二:赞美的六种类型,谨防享受赞美快感如同鱼儿享受诱饵。
Electrical data | IEEE118 (including wind and solar energy)
ClickOnce 不支持请求执行级别“requireAdministrator”
记一个 @nestjs/typeorm^8.1.4 版本不能获取.env选项问题
Mathematical modeling learning from scratch (2): Tools
leetcode刷题_反转字符串中的元音字母
3D vision - 4 Getting started with gesture recognition - using mediapipe includes single frame and real time video
TrueType字体文件提取关键信息
[flask] official tutorial -part2: Blueprint - view, template, static file
Leetcode 208. Implement trie (prefix tree)
[le plus complet du réseau] | interprétation complète de MySQL explicite
竞赛题 2022-6-26
Basic operations of database and table ----- set the fields of the table to be automatically added
Docker compose配置MySQL并实现远程连接
Condition and AQS principle
[detailed] several ways to quickly realize object mapping
黄金价格走势k线图如何看?
Force buckle 1020 Number of enclaves