当前位置:网站首页>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
边栏推荐
- Use of crawler manual 02 requests
- Some features of ECMAScript
- 【已解决】如何生成漂亮的静态文档说明页
- [技术发展-28]:信息通信网大全、新的技术形态、信息通信行业高质量发展概览
- [机缘参悟-39]:鬼谷子-第五飞箝篇 - 警示之二:赞美的六种类型,谨防享受赞美快感如同鱼儿享受诱饵。
- [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.
- Huawei converged VLAN principle and configuration
- 3D视觉——4.手势识别(Gesture Recognition)入门——使用MediaPipe含单帧(Singel Frame)和实时视频(Real-Time Video)
- Live video source code, realize local storage of search history
- How to extract MP3 audio from MP4 video files?
猜你喜欢
ORA-00030
leetcode刷题_平方数之和
The inconsistency between the versions of dynamic library and static library will lead to bugs
Test de vulnérabilité de téléchargement de fichiers basé sur dvwa
Alibaba-Canal使用详解(排坑版)_MySQL与ES数据同步
Dede collection plug-in free collection release push plug-in
Finding the nearest common ancestor of binary search tree by recursion
Electrical data | IEEE118 (including wind and solar energy)
Basic process and testing idea of interface automation
电气数据|IEEE118(含风能太阳能)
随机推荐
现货白银的一般操作方法
基于DVWA的文件上传漏洞测试
ADS-NPU芯片架构设计的五大挑战
晶振是如何起振的?
网易智企逆势进场,游戏工业化有了新可能
Unity VR solves the problem that the handle ray keeps flashing after touching the button of the UI
VMware Tools installation error: unable to automatically install vsock driver
Recommended areas - ways to explore users' future interests
[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.
FFT 学习笔记(自认为详细)
Leetcode skimming questions_ Verify palindrome string II
JMeter BeanShell的基本用法 一下语法只能在beanshell中使用
Leetcode 208. 实现 Trie (前缀树)
XSS learning XSS lab problem solution
A glimpse of spir-v
Building core knowledge points
Convert binary search tree into cumulative tree (reverse middle order traversal)
How to get all sequences in Oracle database- How can I get all sequences in an Oracle database?
Vulhub vulnerability recurrence 75_ XStream
Leetcode skimming questions_ Sum of squares