当前位置:网站首页>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
边栏推荐
- Mysql--- query the top 5 students
- Condition and AQS principle
- Unity | two ways to realize facial drive
- 【全网最全】 |MySQL EXPLAIN 完全解读
- 【已解决】如何生成漂亮的静态文档说明页
- Ubantu check cudnn and CUDA versions
- Une image! Pourquoi l'école t'a - t - elle appris à coder, mais pourquoi pas...
- servlet(1)
- DOM introduction
- SCM Chinese data distribution
猜你喜欢

基於DVWA的文件上傳漏洞測試

A Cooperative Approach to Particle Swarm Optimization

Four commonly used techniques for anti aliasing

Leetcode skimming questions_ Verify palindrome string II

Docker compose配置MySQL并实现远程连接
![[understanding of opportunity-39]: Guiguzi - Chapter 5 flying clamp - warning 2: there are six types of praise. Be careful to enjoy praise as fish enjoy bait.](/img/3c/ec97abfabecb3f0c821beb6cfe2983.jpg)
[understanding of opportunity-39]: Guiguzi - Chapter 5 flying clamp - warning 2: there are six types of praise. Be careful to enjoy praise as fish enjoy bait.

How does the crystal oscillator vibrate?
![[detailed] several ways to quickly realize object mapping](/img/e5/70c7f8fee4556d14f969fe33938971.gif)
[detailed] several ways to quickly realize object mapping

Leetcode study - day 35

ORA-00030
随机推荐
1791. Find the central node of the star diagram / 1790 Can two strings be equal by performing string exchange only once
Code review concerns
普通人下场全球贸易,新一轮结构性机会浮出水面
MYSQL---查询成绩为前5名的学生
【已解决】如何生成漂亮的静态文档说明页
现货白银的一般操作方法
3D vision - 4 Getting started with gesture recognition - using mediapipe includes single frame and real time video
How does Huawei enable debug and how to make an image port
Netease smart enterprises enter the market against the trend, and there is a new possibility for game industrialization
Tcpdump: monitor network traffic
Finding the nearest common ancestor of binary tree by recursion
Code Review关注点
Remember that a version of @nestjs/typeorm^8.1.4 cannot be obtained Env option problem
[le plus complet du réseau] | interprétation complète de MySQL explicite
JVM_ 15_ Concepts related to garbage collection
MySQL learning notes 2
Interview must brush algorithm top101 backtracking article top34
How to get the PHP version- How to get the PHP Version?
XSS learning XSS lab problem solution
BiShe - College Student Association Management System Based on SSM