当前位置:网站首页>[LeetCode] 回文数【9】
[LeetCode] 回文数【9】
2022-07-02 22:06:00 【山茶花开时。】
问题: 给你一个整数x,如果x是一个回文整数,返回True;否则,返回False
回文数是指正序(从左向右)和倒序(从右向左)读都是一样的整数。例如,121是回文,而123不是
示例1
输入: x = 121
输出: True
示例2
输入: x = -121
输出: False
解释: 从左向右读,为-121,从右向左读,为121- ,因此它不是一个回文数
示例3
输入: x = 10
输出: False
解释: 从右向左读,为01,因此它不是一个回文数
def isPalindrome(x):
str_x = str(x)
reverse_str_x = str_x[::-1]
if reverse_str_x == str_x:
return True
else:
return False
isPalindrome(121)
isPalindrome(10)
isPalindrome(-121)
边栏推荐
- Market Research - current situation and future development trend of anti-counterfeiting label market
- 图形视图框架
- 电商系统微服务架构
- Scrcpy this software solves the problem of sharing mobile screen with colleagues | community essay solicitation
- Share how to make professional hand drawn electronic maps
- [autosar-dcm] - 4.3-how UDS $22 and $2e services read and write NVM data
- Technological Entrepreneurship: failure is not success, but reflection is
- Unity publishes a method of webgl playing sound
- Market Research - current situation and future development trend of marine clutch Market
- Market Research - current situation and future development trend of environmental friendly fireworks Market
猜你喜欢
New feature of go1.18: introduce new netip Network Library
Build your own website (22)
kubernetes 使用主机名将 pod 分配在指定节点上
[001] [arm-cortex-m3/4] internal register
Task and privilege level protection
Tencent three sides: in the process of writing files, the process crashes, and will the file data be lost?
An overview of the development of affective computing and understanding research
Hanoi Tower problem
Commodity information management system (C language document version)
[shutter] shutter custom fonts (download TTF fonts | pubspec.yaml configure font resources | synchronize resources | globally apply fonts | locally apply fonts)
随机推荐
【微服务|Sentinel】重写sentinel的接口BlockExceptionHandler
[autosar-dcm] - 4.3-how UDS $22 and $2e services read and write NVM data
Utilisation de simpletk - 4. Question étrange
Jerry's modification does not require long press the boot function [chapter]
[shutter] shutter application life cycle (foreground state resumed | background state paused | inactive | component separation state detached)
ArrayList analysis 2: pits in ITR, listiterator, and sublist
NC24325 [USACO 2012 Mar S]Flowerpot
Source code analysis - lightweight asynchronous crawler framework Ruia
UE4 游戏架构 学习笔记
杰理之内置关机电流 1.2uA,之后不能长按开机【篇】
Necessary browser plug-ins for network security engineers
Oracle-游标
Leetcode circular linked list (fast and slow pointer) code line by line interpretation
Ransack combined condition search implementation
scrcpy这款软件解决了和同事分享手机屏幕的问题| 社区征文
Market Research - current market situation and future development trend of genome editing mutation detection kit
Get off work on time! Episode 6 of Excel Collection - how to split and count document amounts
【AUTOSAR-DCM】-4.3-UDS $22和$2E服务如何读取和写入NVM数据
Simpleitk use - 4 Strange question
Service visibility and observability