当前位置:网站首页>Palindrome number for leetcode topic analysis
Palindrome number for leetcode topic analysis
2022-06-23 06:02:00 【ruochen】
Determine whether an integer is a palindrome. Do this without extra space.
Some hints:
- Could negative integers be palindromes? (ie, -1)
- If you are thinking of converting the integer to string, note the restriction of using extra space.
- You could also try reversing an integer. However, if you have solved the problem "Reverse Integer", you know that the reversed integer might overflow. How would you handle such case?
- There is a more generic way of solving this problem.
public boolean isPalindrome(int x) {
if (x < 0) {
return false;
}
if (x >= 0 && x < 10) {
return true;
}
int d = 1;
while (x / d >= 10) {
d *= 10;
}
while (x != 0) {
if (x % 10 != x / d) {
return false;
}
x = x % d / 10;
d /= 100;
}
return true;
}边栏推荐
猜你喜欢

Real MySQL interview questions (25) -- common group comparison scenarios

Digital collections - new investment opportunities

编址和编址单位
![[image fusion] sparse regularization based on non convex penalty to realize image fusion with matlab code](/img/e2/24eb2a60e3dc603b3ec4bfefd0b8e5.png)
[image fusion] sparse regularization based on non convex penalty to realize image fusion with matlab code

What benefits have digital collections enabled the real industry to release?

Centos7部署radius服务-freeradius-3.0.13-15.el7集成mysql

数字藏品如何赋能经济实体?

jvm-01. Instruction rearrangement

Centos7 deploy radius service -freeradius-3.0.13-15 EL7 integrating MySQL
![[open source project] excel export Lua configuration table tool](/img/3a/8e831c4216494d5497928bae21523b.png)
[open source project] excel export Lua configuration table tool
随机推荐
Visual studio debugging tips
三项最高级认证,两项创新技术、两大优秀案例,阿里云亮相云原生产业大会
SQL表名与函数名相同导致SQL语句错误。
Pat class B 1026 program running time
Pat class B 1013 C language
数字藏品到底有什么魔力?目前有哪些靠谱的团队在开发
Jvm: when a method is overloaded, the specific method to call is determined by the static type of the incoming parameter rather than the actual type of the parameter
About the error of installing PIP3 install chatterbot
PAT 乙等 1015 C语言
Data migration from dolphin scheduler 1.2.1 to dolphin scheduler 2.0.5 and data test records after migration
[cocos2d-x] screenshot sharing function
ant使用总结(一):使用ant自动打包apk
Pat class B 1017 C language
Prometheus, incluxdb2.2 installation and flume_ Export download compile use
Leetcode topic resolution divide two integers
How to specify the output path of pig register Project Log
How does win11 enable mobile hotspot? How to enable mobile hotspot in win11
gplearn出现 assignment destination is read-only
PAT 乙等 1013 C语言
Pat class B 1024 scientific notation C language