当前位置:网站首页>Force buckle 9 palindromes
Force buckle 9 palindromes
2022-07-06 01:25:00 【zjsru_ Beginner】
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 .

My thoughts :
So let's define a long Variable of type y To simulate integers x In reverse order ,
( Why do I use long Type instead of int Type? ? This is because it is easy to encounter the overflow of signed integer numbers ),
Use one while loop , take x The low order of is converted to the high order , take x The high order of is converted to the low order and assigned to y, Last comparison y,x Whether the two are equal .
My code :
class Solution {
public:
bool isPalindrome(int x) {
long y=0;
int num=x;
if(x<0) return false;
while(num!=0){
y=y*10+num%10;
num/=10;
}
return x==y;
}
};

Digital media 202 Pan ZY
边栏推荐
- Leetcode 208. Implement trie (prefix tree)
- 【全網最全】 |MySQL EXPLAIN 完全解讀
- 2020.2.13
- 黄金价格走势k线图如何看?
- Who knows how to modify the data type accuracy of the columns in the database table of Damon
- Nmap: network detection tool and security / port scanner
- 【详细】快速实现对象映射的几种方式
- Docker compose configures MySQL and realizes remote connection
- Ubantu check cudnn and CUDA versions
- Five challenges of ads-npu chip architecture design
猜你喜欢

Dede collection plug-in free collection release push plug-in

A Cooperative Approach to Particle Swarm Optimization

现货白银的一般操作方法

How to extract MP3 audio from MP4 video files?

2020.2.13

Une image! Pourquoi l'école t'a - t - elle appris à coder, mais pourquoi pas...

ORA-00030

Some features of ECMAScript

Pbootcms plug-in automatically collects fake original free plug-ins

Superfluid_ HQ hacked analysis
随机推荐
[detailed] several ways to quickly realize object mapping
Huawei Hrbrid interface and VLAN division based on IP
Cglib dynamic agent -- example / principle
[机缘参悟-39]:鬼谷子-第五飞箝篇 - 警示之二:赞美的六种类型,谨防享受赞美快感如同鱼儿享受诱饵。
Gartner发布2022-2023年八大网络安全趋势预测,零信任是起点,法规覆盖更广
ORA-00030
Docker compose configures MySQL and realizes remote connection
SSH login is stuck and disconnected
Obstacle detection
PHP error what is an error?
Vulhub vulnerability recurrence 75_ XStream
Pbootcms plug-in automatically collects fake original free plug-ins
ctf. Show PHP feature (89~110)
WGet: command line download tool
leetcode刷题_反转字符串中的元音字母
记一个 @nestjs/typeorm^8.1.4 版本不能获取.env选项问题
Leetcode daily question solution: 1189 Maximum number of "balloons"
[the most complete in the whole network] |mysql explain full interpretation
Remember that a version of @nestjs/typeorm^8.1.4 cannot be obtained Env option problem
Leetcode sword finger offer 59 - ii Maximum value of queue