当前位置:网站首页>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 .
边栏推荐
- Paddle framework: paddlenlp overview [propeller natural language processing development library]
- Cookie concept, basic use, principle, details and Chinese transmission
- [technology development -28]: overview of information and communication network, new technology forms, high-quality development of information and communication industry
- A Cooperative Approach to Particle Swarm Optimization
- 2 power view
- How to upgrade kubernetes in place
- Kubernetes stateless application expansion and contraction capacity
- Alibaba canal usage details (pit draining version)_ MySQL and ES data synchronization
- Redis-字符串类型
- [flask] official tutorial -part3: blog blueprint, project installability
猜你喜欢

How does the crystal oscillator vibrate?

Condition and AQS principle

Une image! Pourquoi l'école t'a - t - elle appris à coder, mais pourquoi pas...

A Cooperative Approach to Particle Swarm Optimization

TrueType字体文件提取关键信息

How to upgrade kubernetes in place

MySQL learning notes 2

3D vision - 4 Getting started with gesture recognition - using mediapipe includes single frame and real time video

Ordinary people end up in Global trade, and a new round of structural opportunities emerge
![[机缘参悟-39]:鬼谷子-第五飞箝篇 - 警示之二:赞美的六种类型,谨防享受赞美快感如同鱼儿享受诱饵。](/img/3c/ec97abfabecb3f0c821beb6cfe2983.jpg)
[机缘参悟-39]:鬼谷子-第五飞箝篇 - 警示之二:赞美的六种类型,谨防享受赞美快感如同鱼儿享受诱饵。
随机推荐
Unity VR resource flash surface in scene
记一个 @nestjs/typeorm^8.1.4 版本不能获取.env选项问题
ORA-00030
C web page open WinForm exe
Flowable source code comments (36) process instance migration status job processor, BPMN history cleanup job processor, external worker task completion job processor
3D model format summary
【Flask】官方教程(Tutorial)-part2:蓝图-视图、模板、静态文件
剑指 Offer 38. 字符串的排列
Leetcode1961. 检查字符串是否为数组前缀
【Flask】响应、session与Message Flashing
Docker compose configures MySQL and realizes remote connection
普通人下场全球贸易,新一轮结构性机会浮出水面
ClickOnce does not support request execution level 'requireAdministrator'
CocoaPods could not find compatible versions for pod 'Firebase/CoreOnly'
竞价推广流程
Luo Gu P1170 Bugs Bunny and Hunter
Leetcode sword finger offer 59 - ii Maximum value of queue
A Cooperative Approach to Particle Swarm Optimization
【Flask】获取请求信息、重定向、错误处理
Folio.ink 免费、快速、易用的图片分享工具