当前位置:网站首页>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;
}边栏推荐
- About the error of installing PIP3 install chatterbot
- PAT 乙等 1018 C语言
- The hierarchyviewer tool cannot find the hierarchyviewer location
- 阿里云 ACK One、ACK 云原生 AI 套件新发布,解决算力时代下场景化需求
- Implementation of linear list linked list structure
- The official artifact of station B has cracked itself!
- [Stanford Jiwang cs144 project] lab2: tcpreceiver
- Software design and Development Notes 2: serial port debugging tool based on QT design
- PAT 乙等 1016 C语言
- 三项最高级认证,两项创新技术、两大优秀案例,阿里云亮相云原生产业大会
猜你喜欢
![[OWT] OWT client native P2P E2E test vs2017 build 6: modify script automatic generation vs Project](/img/ce/2e0b0c0f6fae24b5b0df2680229284.png)
[OWT] OWT client native P2P E2E test vs2017 build 6: modify script automatic generation vs Project

Analysis on the problems and causes of digital transformation of manufacturing industry

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

MDM data cleaning function development description

android Handler内存泄露 kotlin内存泄露处理

Activity startup mode and life cycle measurement results

Kotlin android简单Activity跳转、handler和thread简单配合使用

数字藏品到底有什么魔力?目前有哪些靠谱的团队在开发

runc 符号链接挂载与容器逃逸漏洞预警(CVE-2021-30465)

Ant Usage Summary (II): description of related commands
随机推荐
PAT 乙等 1009 C语言
[open source project] excel export Lua configuration table tool
Adnroid activity screenshot save display to album view display picture animation disappear
What is the magic of digital collections? Which reliable teams are currently developing
Advanced Mathematics (Seventh Edition) Tongji University exercises 1-8 personal solutions
Centos7部署radius服务-freeradius-3.0.13-15.el7集成mysql
Pat class B 1010 C language
jvm-01. Instruction rearrangement
Digital collections - new investment opportunities
iNFTnews | 加密之家从宇宙寄来的明信片,你会收到哪一张?
PAT 乙等 1026 程序运行时间
The digital collection market has just begun
HierarchyViewer工具找不到 HierarchyViewer位置
Pat class B 1019 C language
jvm-03. JVM memory model
PAT 乙等 1020.月饼
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
Real MySQL interview questions (25) -- common group comparison scenarios
【Cocos2d-x】自定义环形菜单
TCP/IP 详解(第 2 版) 笔记 / 3 链路层 / 3.4 网桥与交换机