当前位置:网站首页>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
边栏推荐
- 机器学习笔记 - 互信息Mutual Information
- QT - double buffer plot
- 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
- 使用 BlocConsumer 同时构建响应式组件和监听状态
- Redis has three methods for checking big keys, which are necessary for optimization
- # 2156. Find the substring of the given hash value - post order traversal
- 保证接口数据安全的10种方案
- 服装企业为什么要谈信息化?
- i.MX6ULL驱动开发 | 24 - 基于platform平台驱动模型点亮LED
- Kdd2022 | what features are effective for interaction?
猜你喜欢
什么是商业智能(BI),就看这篇文章足够了
KDD2022 | 什么特征进行交互才是有效的?
Use blocconsumer to build responsive components and monitor status at the same time
历史最全混合专家(MOE)模型相关精选论文、系统、应用整理分享
Radio and television Wuzhou signed a cooperation agreement with Huawei to jointly promote the sustainable development of shengteng AI industry
Cloudcompare & open3d DBSCAN clustering (non plug-in)
广电五舟与华为签署合作协议,共同推进昇腾AI产业持续发展
QT - double buffer plot
QT - plot other problems
保证接口数据安全的10种方案
随机推荐
HDU - 1078 FatMouse and Cheese(记忆化搜索DP)
Xiangjiang Kunpeng joined the shengteng Wanli partnership program and continued to write a new chapter of cooperation with Huawei
Caduceus从未停止创新,去中心化边缘渲染技术让元宇宙不再遥远
开户哪家券商比较好?网上开户安全吗
Spatiotemporal prediction 3-graph transformer
Enlightenment of maker thinking in Higher Education
PostgreSQL基本结构——表
DevEco Device Tool 3.0 Release带来5大能力升级,让智能设备开发更高效
AscendEX 上线 Walken (WLKN) - 一款卓越领先的“Walk-to-Earn”游戏
Redis 排查大 key 的3种方法,优化必备
Telephone encryption, middle 4 is replaced by * * * *
NAACL-22 | 在基于Prompt的文本生成任务上引入迁移学习的设置
QT - double buffer plot
Radio and television Wuzhou signed a cooperation agreement with Huawei to jointly promote the sustainable development of shengteng AI industry
VIM from dislike to dependence (23) -- the last gossip
1807. Replace the parentheses in the string
大厂的广告系统升级,怎能少了大模型的身影
Interpreting the development of various intelligent organizations in maker Education
Which securities company is better to open an account? Is online account opening safe
Implementation rules for archiving assessment materials of robot related courses 2022 version