当前位置:网站首页>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
边栏推荐
- Nat. Commun.| Machine learning jointly optimizes the affinity and specificity of mutagenic therapeutic antibodies
- 关系型数据库
- i.MX6ULL驱动开发 | 24 - 基于platform平台驱动模型点亮LED
- What is business intelligence (BI), just look at this article is enough
- Enlightenment of maker thinking in Higher Education
- Convolutional neural network model -- lenet network structure and code implementation
- 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
- 力扣3_383. 赎金信
- Open3D 曲面法向量计算
- Operation of adding material schedule in SolidWorks drawing
猜你喜欢
Keep on fighting! The city chain technology digital summit was grandly held in Chongqing
案例分享|金融业数据运营运维一体化建设
复数在数论、几何中的用途 - 曹则贤
i. Mx6ull driver development | 24 - platform based driver model lights LED
一文掌握数仓中auto analyze的使用
GTEST from ignorance to proficiency (3) what are test suite and test case
É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)
TCP protocol three times handshake process
Ascendex launched Walken (WLKN) - an excellent and leading "walk to earn" game
【米哈游2023届秋招】开启【校招唯一专属内推码EYTUC】
随机推荐
MySQL存储数据加密
挖财学院股票开户安全吗?开户只能在挖财开户嘛?
广电五舟与华为签署合作协议,共同推进昇腾AI产业持续发展
Interview question 01.01 Determine whether the character is unique
Hash table
ApacheCN 翻译、校对、笔记整理活动进度公告 2022.7
并发优化总结
283. 移动零-c与语言辅助数组法
Acwing 2022 daily question
gtest从一无所知到熟练使用(2)什么是测试夹具/装置(test fixture)
复数在数论、几何中的用途 - 曹则贤
NAACL-22 | 在基于Prompt的文本生成任务上引入迁移学习的设置
Basic structure of PostgreSQL - table
能源势动:电力行业的碳中和该如何实现?
哈希表(Hash Tabel)
Energy momentum: how to achieve carbon neutralization in the power industry?
Application practice | Shuhai supply chain construction of data center based on Apache Doris
TCP protocol three times handshake process
KDD2022 | 什么特征进行交互才是有效的?
1807. 替换字符串中的括号内容