当前位置:网站首页>Force buckle_ Palindrome number
Force buckle_ Palindrome number
2022-07-04 22:11:00 【Don't sleep in class】
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 .
Example 1:
Input :x = 121
Output :true
Example 2:
Input :x = -121
Output :false
explain : Read left to right , by -121 . Read right to left , by 121- . So it's not a palindrome number .
Example 3:
Input :x = 10
Output :false
explain : Read right to left , by 01 . So it's not a palindrome number .
source : Power button (LeetCode)
Java solution
class Solution {
public boolean isPalindrome(int x) {
if(x<0||(x%10==0&&x!=0)){
// Exclude negative numbers and the last digit is 0 Number of numbers
return false;
}
int revertedNumber=0;
while(x>revertedNumber){
revertedNumber=revertedNumber*10+x%10;
x/=10;
// Reverse the second half of this number
}
return x==revertedNumber||x==revertedNumber/10;
}
}
Python solution
class Solution:
def isPalindrome(self, x: int) -> bool:
s=str(x)
l=len(s)
h=l//2
return s[:h]==s[-1:-h-1:-1]
# the last one -1 Indicates flashback output , The first two values represent the range
边栏推荐
- 力扣_回文数
- Exclusive interview of open source summer | new committer Xie Qijun of Apache iotdb community
- 文件读取写入
- 广电五舟与华为签署合作协议,共同推进昇腾AI产业持续发展
- # 2156. Find the substring of the given hash value - post order traversal
- ACM Multimedia 2022 | 视觉语言预训练模型中社会偏见的反事实衡量和消除
- Representation of confidence interval
- Keep on fighting! The city chain technology digital summit was grandly held in Chongqing
- 能源势动:电力行业的碳中和该如何实现?
- bizchart+slider实现分组柱状图
猜你喜欢

TCP protocol three times handshake process

El tree combined with El table, tree adding and modifying operations

使用 BlocConsumer 同时构建响应式组件和监听状态

Zhiyang innovation signed a cooperation agreement with Huawei to jointly promote the sustainable development of shengteng AI industry
![[optimtool.unconstrained] unconstrained optimization toolbox](/img/ef/65379499df205c068ee9bc9df797ac.png)
[optimtool.unconstrained] unconstrained optimization toolbox

KDD2022 | 什么特征进行交互才是有效的?

VS2019 C# release下断点调试

能源势动:电力行业的碳中和该如何实现?

Sorting and sharing of selected papers, systems and applications related to the most comprehensive mixed expert (MOE) model in history

i.MX6ULL驱动开发 | 24 - 基于platform平台驱动模型点亮LED
随机推荐
Enabling digital economy Fuxin software attends the BRICs high level Forum on Sustainable Development
# 2156. Find the substring of the given hash value - post order traversal
Éducation à la transmission du savoir | Comment passer à un test logiciel pour l'un des postes les mieux rémunérés sur Internet? (joindre la Feuille de route pour l'apprentissage des tests logiciels)
【Acwing】第58场周赛 题解
New intersectionobserver usage notes
bizchart+slider实现分组柱状图
复数在数论、几何中的用途 - 曹则贤
Basic structure of PostgreSQL - table
服装企业为什么要谈信息化?
ApacheCN 翻译、校对、笔记整理活动进度公告 2022.7
NAACL-22 | 在基于Prompt的文本生成任务上引入迁移学习的设置
WebGIS framework -- kalrry
AcWing 2022 每日一题
Why should garment enterprises talk about informatization?
MongoDB中的索引操作总结
网上开户哪家证券公司佣金最低,我要开户,网上开户安全吗
A large number of virtual anchors in station B were collectively forced to refund: revenue evaporated, but they still owe station B; Jobs was posthumously awarded the U.S. presidential medal of freedo
Visual task scheduling & drag and drop | scalph data integration based on Apache seatunnel
CloudCompare&Open3D DBSCAN聚类(非插件式)
i. Mx6ull driver development | 24 - platform based driver model lights LED