当前位置:网站首页>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
边栏推荐
- Finding the nearest common ancestor of binary tree by recursion
- JMeter BeanShell的基本用法 一下语法只能在beanshell中使用
- Folio.ink 免费、快速、易用的图片分享工具
- GNSS terminology
- ORA-00030
- [day 30] given an integer n, find the sum of its factors
- Yii console method call, Yii console scheduled task
- Three methods of script about login and cookies
- 什么是弱引用?es6中有哪些弱引用数据类型?js中的弱引用是什么?
- Finding the nearest common ancestor of binary search tree by recursion
猜你喜欢

MATLB|实时机会约束决策及其在电力系统中的应用

3D视觉——4.手势识别(Gesture Recognition)入门——使用MediaPipe含单帧(Singel Frame)和实时视频(Real-Time Video)

Some features of ECMAScript

Introduction to robotics I. spatial transformation (1) posture, transformation

3D模型格式汇总

Kotlin basics 1

【详细】快速实现对象映射的几种方式

A picture to understand! Why did the school teach you coding but still not

VMware Tools安装报错:无法自动安装VSock驱动程序

【SSRF-01】服务器端请求伪造漏洞原理及利用实例
随机推荐
Yii console method call, Yii console scheduled task
Vulhub vulnerability recurrence 75_ XStream
General operation method of spot Silver
Nmap: network detection tool and security / port scanner
About error 2003 (HY000): can't connect to MySQL server on 'localhost' (10061)
Differences between standard library functions and operators
The growth path of test / development programmers, the problem of thinking about the overall situation
Huawei Hrbrid interface and VLAN division based on IP
servlet(1)
The basic usage of JMeter BeanShell. The following syntax can only be used in BeanShell
Some features of ECMAScript
Crawler request module
Live video source code, realize local storage of search history
【第30天】给定一个整数 n ,求它的因数之和
How does Huawei enable debug and how to make an image port
ORA-00030
Folio.ink 免费、快速、易用的图片分享工具
GNSS terminology
1791. Find the central node of the star diagram / 1790 Can two strings be equal by performing string exchange only once
MATLB|实时机会约束决策及其在电力系统中的应用