当前位置:网站首页>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
边栏推荐
- QT—绘制其他问题
- HDU - 1078 fatmouse and cheese (memory search DP)
- Enlightenment of maker thinking in Higher Education
- Interview question 01.01 Determine whether the character is unique
- Spatiotemporal prediction 3-graph transformer
- PMO:比较25种分子优化方法的样本效率
- 服装企业为什么要谈信息化?
- QT - plot other problems
- 湘江鲲鹏加入昇腾万里伙伴计划,与华为续写合作新篇章
- Implementation rules for archiving assessment materials of robot related courses 2022 version
猜你喜欢

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

TLA+ 入门教程(1):形式化方法简介

Analyzing the maker space contained in steam Education

Application practice | Shuhai supply chain construction of data center based on Apache Doris
![[advanced C language] array & pointer & array written test questions](/img/3f/83801afba153cfc0dd73aa8187ef20.png)
[advanced C language] array & pointer & array written test questions

Case sharing | integrated construction of data operation and maintenance in the financial industry

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

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

案例分享|金融业数据运营运维一体化建设
随机推荐
Xiangjiang Kunpeng joined the shengteng Wanli partnership program and continued to write a new chapter of cooperation with Huawei
Solve the problem of data disorder caused by slow asynchronous interface
New intersectionobserver usage notes
# 2156. Find the substring of the given hash value - post order traversal
Interview question 01.01 Determine whether the character is unique
gtest从一无所知到熟练使用(2)什么是测试夹具/装置(test fixture)
《命令行上的数据科学第二版》校对活动重新启动
QT—绘制其他问题
开户哪家券商比较好?网上开户安全吗
Enabling digital economy Fuxin software attends the BRICs high level Forum on Sustainable Development
机器学习笔记 - 互信息Mutual Information
力扣98:验证二叉搜索树
Interpreting the development of various intelligent organizations in maker Education
玩转gRPC—深入概念与原理
VIM from dislike to dependence (23) -- the last gossip
283. Moving zero-c and language assisted array method
Bookmark
Keep on fighting! The city chain technology digital summit was grandly held in Chongqing
PostgreSQL基本结构——表
How to implement Devops with automatic tools