当前位置:网站首页>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 .
边栏推荐
- 现货白银的一般操作方法
- Leetcode skimming questions_ Invert vowels in a string
- 3D模型格式汇总
- Redis-字符串类型
- Loop structure of program (for loop)
- Leetcode 208. Implement trie (prefix tree)
- Unity VR resource flash surface in scene
- 什么是弱引用?es6中有哪些弱引用数据类型?js中的弱引用是什么?
- Cookie concept, basic use, principle, details and Chinese transmission
- dried food! Accelerating sparse neural network through hardware and software co design
猜你喜欢

Superfluid_ HQ hacked analysis

电气数据|IEEE118(含风能太阳能)

Alibaba canal usage details (pit draining version)_ MySQL and ES data synchronization

Kubernetes stateless application expansion and contraction capacity

Redis-列表

About error 2003 (HY000): can't connect to MySQL server on 'localhost' (10061)
![[flask] official tutorial -part1: project layout, application settings, definition and database access](/img/c3/04422e4c6c1247169999dd86b74c05.png)
[flask] official tutorial -part1: project layout, application settings, definition and database access

Leetcode skimming questions_ Sum of squares

How to see the K-line chart of gold price trend?

1. Introduction to basic functions of power query
随机推荐
Cookie concept, basic use, principle, details and Chinese transmission
Nmap: network detection tool and security / port scanner
WGet: command line download tool
01.Go语言介绍
2022 Guangxi Autonomous Region secondary vocational group "Cyberspace Security" competition and its analysis (super detailed)
【已解决】如何生成漂亮的静态文档说明页
LeetCode 322. Change exchange (dynamic planning)
PHP error what is an error?
DOM introduction
02.Go语言开发环境配置
MCU lightweight system core
ClickOnce does not support request execution level 'requireAdministrator'
什么是弱引用?es6中有哪些弱引用数据类型?js中的弱引用是什么?
[Yu Yue education] Liaoning Vocational College of Architecture Web server application development reference
[机缘参悟-39]:鬼谷子-第五飞箝篇 - 警示之二:赞美的六种类型,谨防享受赞美快感如同鱼儿享受诱饵。
D22:indeterminate equation (indefinite equation, translation + problem solution)
Open source | Ctrip ticket BDD UI testing framework flybirds
3D模型格式汇总
Kotlin basics 1
How to get the PHP version- How to get the PHP Version?