当前位置:网站首页>[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)边栏推荐
- Mathematical modeling -- graph and network models and methods (I)
- UE4 game architecture learning notes
- Pointer array parameter passing, pointer parameter passing
- 杰理之样机无触摸,拆机之后重新安装变正常【篇】
- Leetcode circular linked list (fast and slow pointer) code line by line interpretation
- #include errors detected. Please update your includePath.
- Using rendertext() to output multiple lines of text with rendertext() in R shiny
- Web side defense Guide
- 《乔布斯传》英文原著重点词汇笔记(九)【 chapter seven】
- PMP项目整合管理
猜你喜欢
随机推荐
NC24325 [USACO 2012 Mar S]Flowerpot
电商系统微服务架构
php实现根据输入的年龄查询出生日期符合的数据
Introduction to database system Chapter 1 short answer questions - how was the final exam?
Share how to make professional hand drawn electronic maps
Market Research - current situation and future development trend of carob chocolate market
Unity publishes a method of webgl playing sound
I admire that someone explained such an obscure subject as advanced mathematics so easily
Market Research - current market situation and future development trend of genome editing mutation detection kit
杰理之快速触摸不响应问题【篇】
Try to get property'num for PHP database data reading_ rows' of non-object?
Reading experience of just because
百度智能云-创建人脸识别应用
数学建模——图与网络模型及方法(一)
JS solution for obtaining the width and height of hidden elements whose display is none
Oracle cursor
540. Single element in ordered array
Micro service gateway selection, please accept my knees!
#include errors detected. Please update your includePath.
存储单位换算









