当前位置:网站首页>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 .
边栏推荐
- UE4 unreal engine, editor basic application, usage skills (IV)
- Code Review关注点
- leetcode刷题_平方数之和
- A Cooperative Approach to Particle Swarm Optimization
- Force buckle 1020 Number of enclaves
- 3D视觉——4.手势识别(Gesture Recognition)入门——使用MediaPipe含单帧(Singel Frame)和实时视频(Real-Time Video)
- Format code_ What does formatting code mean
- Paddle framework: paddlenlp overview [propeller natural language processing development library]
- 【SSRF-01】服务器端请求伪造漏洞原理及利用实例
- 一圖看懂!為什麼學校教了你Coding但還是不會的原因...
猜你喜欢

Poj2315 football games

TrueType字体文件提取关键信息

Accelerating spark data access with alluxio in kubernetes

selenium 等待方式

Kubernetes stateless application expansion and contraction capacity

Huawei Hrbrid interface and VLAN division based on IP

Basic operations of databases and tables ----- unique constraints
![[机缘参悟-39]:鬼谷子-第五飞箝篇 - 警示之二:赞美的六种类型,谨防享受赞美快感如同鱼儿享受诱饵。](/img/3c/ec97abfabecb3f0c821beb6cfe2983.jpg)
[机缘参悟-39]:鬼谷子-第五飞箝篇 - 警示之二:赞美的六种类型,谨防享受赞美快感如同鱼儿享受诱饵。

【SSRF-01】服务器端请求伪造漏洞原理及利用实例
![[flask] official tutorial -part2: Blueprint - view, template, static file](/img/bd/a736d45d7154119e75428f227af202.png)
[flask] official tutorial -part2: Blueprint - view, template, static file
随机推荐
Unity VR solves the problem that the handle ray keeps flashing after touching the button of the UI
2022年广西自治区中职组“网络空间安全”赛题及赛题解析(超详细)
A glimpse of spir-v
How does the crystal oscillator vibrate?
MATLB|实时机会约束决策及其在电力系统中的应用
Code review concerns
Force buckle 1020 Number of enclaves
About error 2003 (HY000): can't connect to MySQL server on 'localhost' (10061)
MCU lightweight system core
[flask] obtain request information, redirect and error handling
You are using pip version 21.1.1; however, version 22.0.3 is available. You should consider upgradin
[flask] static file and template rendering
一图看懂!为什么学校教了你Coding但还是不会的原因...
普通人下场全球贸易,新一轮结构性机会浮出水面
Basic operations of database and table ----- delete data table
晶振是如何起振的?
电气数据|IEEE118(含风能太阳能)
干货!通过软硬件协同设计加速稀疏神经网络
Comments on flowable source code (XXXV) timer activation process definition processor, process instance migration job processor
Leetcode 剑指 Offer 59 - II. 队列的最大值