当前位置:网站首页>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
边栏推荐
- Remember that a version of @nestjs/typeorm^8.1.4 cannot be obtained Env option problem
- Mathematical modeling learning from scratch (2): Tools
- Loop structure of program (for loop)
- What is weak reference? What are the weak reference data types in ES6? What are weak references in JS?
- ORA-00030
- Leetcode 剑指 Offer 59 - II. 队列的最大值
- Code Review关注点
- Ordinary people end up in Global trade, and a new round of structural opportunities emerge
- 3D模型格式汇总
- JMeter BeanShell的基本用法 一下语法只能在beanshell中使用
猜你喜欢
伦敦银走势中的假突破
BiShe - College Student Association Management System Based on SSM
leetcode刷题_反转字符串中的元音字母
一圖看懂!為什麼學校教了你Coding但還是不會的原因...
Threedposetracker project resolution
Kotlin basics 1
3D vision - 4 Getting started with gesture recognition - using mediapipe includes single frame and real time video
Pbootcms plug-in automatically collects fake original free plug-ins
基于DVWA的文件上传漏洞测试
Hcip---ipv6 experiment
随机推荐
普通人下场全球贸易,新一轮结构性机会浮出水面
有谁知道 达梦数据库表的列的数据类型 精度怎么修改呀
Nmap: network detection tool and security / port scanner
Huawei converged VLAN principle and configuration
Basic process and testing idea of interface automation
直播系统代码,自定义软键盘样式:字母、数字、标点三种切换
Kotlin basics 1
2020.2.13
Crawler request module
Idea sets the default line break for global newly created files
Cglib dynamic agent -- example / principle
Code Review关注点
ORA-00030
Convert binary search tree into cumulative tree (reverse middle order traversal)
Test de vulnérabilité de téléchargement de fichiers basé sur dvwa
c#网页打开winform exe
3D model format summary
Electrical data | IEEE118 (including wind and solar energy)
Leetcode study - day 35
在产业互联网时代,将会凭借大的产业范畴,实现足够多的发展