当前位置:网站首页>leetcode-9:回文数
leetcode-9:回文数
2022-07-05 05:46:00 【菊头蝙蝠】
题目
给你一个整数 x ,如果 x 是一个回文整数,返回 true ;否则,返回 false 。
回文数是指正序(从左向右)和倒序(从右向左)读都是一样的整数。
- 例如,121 是回文,而 123 不是。
示例 1:
输入:x = 121
输出:true
示例 2:
输入:x = -121
输出:false
解释:从左向右读, 为 -121 。 从右向左读, 为 121- 。因此它不是一个回文数。
示例 3:
输入:x = 10
输出:false
解释:从右向左读, 为 01 。因此它不是一个回文数。
解题
方法一:双指针
class Solution {
public:
bool isPalindrome(int x) {
string s=to_string(x);
int left=0,right=s.size()-1;
while(left<right){
if(s[left]!=s[right]) return false;
left++;
right--;
}
return true;
}
};
边栏推荐
- Analysis of backdoor vulnerability in remote code execution penetration test / / phpstudy of national game title of national secondary vocational network security B module
- 剑指 Offer 35.复杂链表的复制
- 【Jailhouse 文章】Jailhouse Hypervisor
- Wazuh開源主機安全解决方案的簡介與使用體驗
- Drawing dynamic 3D circle with pure C language
- [practical skills] technical management of managers with non-technical background
- CF1637E Best Pair
- 个人开发的渗透测试工具Satania v1.2更新
- Control unit
- 读者写者模型
猜你喜欢
F - Two Exam(AtCoder Beginner Contest 238)
AtCoder Grand Contest 013 E - Placing Squares
Gbase database helps the development of digital finance in the Bay Area
[practical skills] how to do a good job in technical training?
剑指 Offer 35.复杂链表的复制
Smart construction site "hydropower energy consumption online monitoring system"
Introduction and experience of wazuh open source host security solution
[practical skills] technical management of managers with non-technical background
智慧工地“水电能耗在线监测系统”
【云原生】微服务之Feign自定义配置的记录
随机推荐
2022年貴州省職業院校技能大賽中職組網絡安全賽項規程
kubeadm系列-02-kubelet的配置和启动
Mysql database (I)
用STM32点个灯
How to adjust bugs in general projects ----- take you through the whole process by hand
ALU逻辑运算单元
过拟合与正则化
剑指 Offer 35.复杂链表的复制
Solution to the palindrome string (Luogu p5041 haoi2009)
读者写者模型
全国中职网络安全B模块之国赛题远程代码执行渗透测试 //PHPstudy的后门漏洞分析
2022 极术通讯-Arm 虚拟硬件加速物联网软件开发
sync. Interpretation of mutex source code
每日一题-搜索二维矩阵ps二维数组的查找
Convolution neural network -- convolution layer
Pointnet++ learning
Daily question 2013 Detect square
Sword finger offer 09 Implementing queues with two stacks
SAP method of modifying system table data
Daily question - Search two-dimensional matrix PS two-dimensional array search