当前位置:网站首页>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 .
边栏推荐
- MATLB|实时机会约束决策及其在电力系统中的应用
- Alibaba canal usage details (pit draining version)_ MySQL and ES data synchronization
- A glimpse of spir-v
- Leetcode skimming questions_ Invert vowels in a string
- [flask] obtain request information, redirect and error handling
- 晶振是如何起振的?
- Threedposetracker project resolution
- Redis-Key的操作
- National intangible cultural heritage inheritor HD Wang's shadow digital collection of "Four Beauties" made an amazing debut!
- Une image! Pourquoi l'école t'a - t - elle appris à coder, mais pourquoi pas...
猜你喜欢
NLP第四范式:Prompt概述【Pre-train,Prompt(提示),Predict】【刘鹏飞】
Threedposetracker project resolution
How to see the K-line chart of gold price trend?
【Flask】官方教程(Tutorial)-part2:蓝图-视图、模板、静态文件
一圖看懂!為什麼學校教了你Coding但還是不會的原因...
3D模型格式汇总
About error 2003 (HY000): can't connect to MySQL server on 'localhost' (10061)
Yii console method call, Yii console scheduled task
ORA-00030
3D model format summary
随机推荐
2022年广西自治区中职组“网络空间安全”赛题及赛题解析(超详细)
Leetcode 208. Implement trie (prefix tree)
leetcode刷题_反转字符串中的元音字母
Alibaba-Canal使用详解(排坑版)_MySQL与ES数据同步
MATLB|实时机会约束决策及其在电力系统中的应用
Accelerating spark data access with alluxio in kubernetes
Huawei converged VLAN principle and configuration
General operation method of spot Silver
About error 2003 (HY000): can't connect to MySQL server on 'localhost' (10061)
ClickOnce does not support request execution level 'requireAdministrator'
SPIR-V初窥
网易智企逆势进场,游戏工业化有了新可能
Force buckle 9 palindromes
[Jiudu OJ 09] two points to find student information
How does the crystal oscillator vibrate?
Cookie concept, basic use, principle, details and Chinese transmission
MySQL learning notes 2
Tcpdump: monitor network traffic
Unreal browser plug-in
一圖看懂!為什麼學校教了你Coding但還是不會的原因...