当前位置:网站首页>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 .
边栏推荐
猜你喜欢

Maya hollowed out modeling

dried food! Accelerating sparse neural network through hardware and software co design

Initialize MySQL database when docker container starts

leetcode刷题_反转字符串中的元音字母
![[technology development -28]: overview of information and communication network, new technology forms, high-quality development of information and communication industry](/img/94/05b2ff62a8a11340cc94c69645db73.png)
[technology development -28]: overview of information and communication network, new technology forms, high-quality development of information and communication industry

National intangible cultural heritage inheritor HD Wang's shadow digital collection of "Four Beauties" made an amazing debut!

NLP第四范式:Prompt概述【Pre-train,Prompt(提示),Predict】【刘鹏飞】

Redis-列表

Poj2315 football games

Docker compose configures MySQL and realizes remote connection
随机推荐
Leetcode1961. Check whether the string is an array prefix
Kubernetes stateless application expansion and contraction capacity
Dynamics 365 开发协作最佳实践思考
MCU lightweight system core
How to see the K-line chart of gold price trend?
Win10 add file extension
Idea sets the default line break for global newly created files
Code Review关注点
500 lines of code to understand the principle of mecached cache client driver
Folio. Ink is a free, fast and easy-to-use image sharing tool
NiO related knowledge (II)
1. Introduction to basic functions of power query
【全网最全】 |MySQL EXPLAIN 完全解读
Redis-Key的操作
Ordinary people end up in Global trade, and a new round of structural opportunities emerge
[solved] how to generate a beautiful static document description page
【全網最全】 |MySQL EXPLAIN 完全解讀
[技术发展-28]:信息通信网大全、新的技术形态、信息通信行业高质量发展概览
Leetcode skimming questions_ Invert vowels in a string
[flask] static file and template rendering