当前位置:网站首页>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
边栏推荐
- sqlserver对数据进行加密、解密
- Redis has three methods for checking big keys, which are necessary for optimization
- new IntersectionObserver 使用笔记
- 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
- 哈希表(Hash Tabel)
- Use blocconsumer to build responsive components and monitor status at the same time
- AscendEX 上线 Walken (WLKN) - 一款卓越领先的“Walk-to-Earn”游戏
- Implementation rules for archiving assessment materials of robot related courses 2022 version
- 并列图的画法,多排多列
- Deveco device tool 3.0 release brings five capability upgrades to make intelligent device development more efficient
猜你喜欢
How to remove the black dot in front of the title in word document
并发优化总结
迷失在Mysql的锁世界
el-tree结合el-table,树形添加修改操作
案例分享|金融业数据运营运维一体化建设
B站大量虚拟主播被集体强制退款:收入蒸发,还倒欠B站;乔布斯被追授美国总统自由勋章;Grafana 9 发布|极客头条
【C语言进阶篇】数组&&指针&&数组笔试题
卷积神经网络模型之——LeNet网络结构与代码实现
Interpreting the development of various intelligent organizations in maker Education
VS2019 C# release下断点调试
随机推荐
Machine learning notes mutual information
删库不必跑路!详解 MySQL 数据恢复
解决异步接口慢导致的数据错乱问题
Relational database
Bookmark
广电五舟与华为签署合作协议,共同推进昇腾AI产业持续发展
# 2156. Find the substring of the given hash value - post order traversal
ACM Multimedia 2022 | 视觉语言预训练模型中社会偏见的反事实衡量和消除
Open3d surface normal vector calculation
文件读取写入
机器学习笔记 - 互信息Mutual Information
QT—双缓冲绘图
Which securities company has the lowest Commission for opening an account online? I want to open an account. Is it safe to open an account online
Representation of confidence interval
Analyzing the maker space contained in steam Education
Interview question 01.01 Determine whether the character is unique
Bizchart+slider to realize grouping histogram
From repvgg to mobileone, including mobileone code
Kdd2022 | what features are effective for interaction?
并发网络模块化 读书笔记转