当前位置:网站首页>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 .
边栏推荐
- 3D vision - 4 Getting started with gesture recognition - using mediapipe includes single frame and real time video
- How does Huawei enable debug and how to make an image port
- [flask] static file and template rendering
- False breakthroughs in the trend of London Silver
- How to get the PHP version- How to get the PHP Version?
- A Cooperative Approach to Particle Swarm Optimization
- [flask] official tutorial -part3: blog blueprint, project installability
- 【Flask】响应、session与Message Flashing
- Redis守护进程无法停止解决方案
- You are using pip version 21.1.1; however, version 22.0.3 is available. You should consider upgradin
猜你喜欢

02.Go语言开发环境配置

干货!通过软硬件协同设计加速稀疏神经网络

Threedposetracker project resolution

黄金价格走势k线图如何看?

普通人下场全球贸易,新一轮结构性机会浮出水面

Basic operations of databases and tables ----- default constraints

一图看懂!为什么学校教了你Coding但还是不会的原因...

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

3D模型格式汇总

A picture to understand! Why did the school teach you coding but still not
随机推荐
[solved] how to generate a beautiful static document description page
Redis-字符串类型
MATLB|实时机会约束决策及其在电力系统中的应用
[技术发展-28]:信息通信网大全、新的技术形态、信息通信行业高质量发展概览
How does Huawei enable debug and how to make an image port
3D model format summary
Force buckle 1020 Number of enclaves
Leetcode skimming questions_ Sum of squares
dried food! Accelerating sparse neural network through hardware and software co design
ClickOnce 不支持请求执行级别“requireAdministrator”
Une image! Pourquoi l'école t'a - t - elle appris à coder, mais pourquoi pas...
Leetcode1961. 检查字符串是否为数组前缀
NLP fourth paradigm: overview of prompt [pre train, prompt, predict] [Liu Pengfei]
How does the crystal oscillator vibrate?
Initialize MySQL database when docker container starts
A Cooperative Approach to Particle Swarm Optimization
Unity VR solves the problem that the handle ray keeps flashing after touching the button of the UI
How to upgrade kubernetes in place
[flask] static file and template rendering
SPIR-V初窺