当前位置:网站首页>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;
}边栏推荐
猜你喜欢

What is the magic of digital collections? Which reliable teams are currently developing

Prometheus, incluxdb2.2 installation and flume_ Export download compile use
![[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

jvm-04. Object's memory layout

jvm-03.jvm内存模型

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

技术开发团队视角看到的数字藏品机遇与挑战

Advanced Mathematics (Seventh Edition) Tongji University exercises 1-8 personal solutions

新课上线 | 每次 5 分钟,轻松玩转阿里云容器服务!

Centos7 deploy radius service -freeradius-3.0.13-15 EL7 integrating MySQL
随机推荐
Visdom draws multiple dynamic loss curves
Memory analysis and memory leak detection
True MySQL interview question (XXII) -- condition screening and grouping screening after table connection
android Handler内存泄露 kotlin内存泄露处理
关于安装pip3 install chatterbot报错的问题
New classes are launched | 5 minutes each time, you can easily play with Alibaba cloud container service!
PAT 乙等 1016 C语言
Prometheus, incluxdb2.2 installation and flume_ Export download compile use
Kotlin Android simple activity jump, simple combination of handler and thread
Centos7部署radius服务-freeradius-3.0.13-15.el7集成mysql
PAT 乙等 1014 C语言
PAT 乙等 1023 组个最小数
pyinstaller 打包exe设置图标不显示
Operating mongodb in node
The traditional Internet like platform may no longer exist, and a new industry integrating industrial characteristics and Internet characteristics
Pat class B 1019 C language
雷达图canvas
PAT 乙等 1018 C语言
Leetcode topic analysis: factorial training zeroes
Leetcode topic analysis add binary