当前位置:网站首页>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
边栏推荐
- 复数在数论、几何中的用途 - 曹则贤
- Solana链上应用Crema因黑客攻击停运
- TCP协议三次握手过程
- El tree combined with El table, tree adding and modifying operations
- Solve the problem of data disorder caused by slow asynchronous interface
- QT—双缓冲绘图
- ApacheCN 翻译、校对、笔记整理活动进度公告 2022.7
- Operation of adding material schedule in SolidWorks drawing
- What is business intelligence (BI), just look at this article is enough
- 广电五舟与华为签署合作协议,共同推进昇腾AI产业持续发展
猜你喜欢

湘江鲲鹏加入昇腾万里伙伴计划,与华为续写合作新篇章

一文掌握数仓中auto analyze的使用

什么是商业智能(BI),就看这篇文章足够了

GTEST from ignorance to proficiency (3) what are test suite and test case

How to remove the black dot in front of the title in word document

案例分享|金融业数据运营运维一体化建设

Exclusive interview of open source summer | new committer Xie Qijun of Apache iotdb community

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

Analyzing the maker space contained in steam Education

Scala下载和配置
随机推荐
Super detailed tutorial, an introduction to istio Architecture Principle and practical application
sqlserver对数据进行加密、解密
Kdd2022 | what features are effective for interaction?
一文掌握数仓中auto analyze的使用
面试题 01.08. 零矩阵
挖财学院股票开户安全吗?开户只能在挖财开户嘛?
Deveco device tool 3.0 release brings five capability upgrades to make intelligent device development more efficient
el-tree结合el-table,树形添加修改操作
Case sharing | integrated construction of data operation and maintenance in the financial industry
MySQL存储数据加密
KDD2022 | 什么特征进行交互才是有效的?
El tree combined with El table, tree adding and modifying operations
close系统调用分析-性能优化
淘宝商品评价api接口(item_review-获得淘宝商品评论API接口),天猫商品评论API接口
Is it safe to open an account in the stock of Caicai college? Can you only open an account by digging money?
Representation of confidence interval
服务线上治理
HDU - 2859 Phalanx(DP)
What is the stock account opening process? Is it safe to use flush mobile stock trading software?
Relational database