当前位置:网站首页>Leetcode-9: palindromes
Leetcode-9: palindromes
2022-07-05 06:09:00 【Chrysanthemum headed bat】
leetcode-9: Palindrome number
subject
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 .
Example 1:
Input :x = 121
Output :true
Example 2:
Input :x = -121
Output :false
explain : Read left to right , by -121 . Read right to left , by 121- . So it's not a palindrome number .
Example 3:
Input :x = 10
Output :false
explain : Read right to left , by 01 . So it's not a palindrome number .
Problem solving
Method 1 : Double pointer
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;
}
};
边栏推荐
- Matrixdb V4.5.0 was launched with a new mars2 storage engine!
- F - Two Exam(AtCoder Beginner Contest 238)
- leetcode-556:下一个更大元素 III
- Convolution neural network -- convolution layer
- 智慧工地“水电能耗在线监测系统”
- CF1634E Fair Share
- A reason that is easy to be ignored when the printer is offline
- Navicat連接Oracle數據庫報錯ORA-28547或ORA-03135
- 【Rust 笔记】13-迭代器(中)
- 【Rust 笔记】15-字符串与文本(下)
猜你喜欢
实时时钟 (RTC)
Introduction et expérience de wazuh open source host Security Solution
7. Processing the input of multidimensional features
从Dijkstra的图灵奖演讲论科技创业者特点
[cloud native] record of feign custom configuration of microservices
Matrixdb V4.5.0 was launched with a new mars2 storage engine!
Sqlmap tutorial (1)
[jailhouse article] performance measurements for hypervisors on embedded ARM processors
Appium automation test foundation - Summary of appium test environment construction
In this indifferent world, light crying
随机推荐
【Rust 笔记】15-字符串与文本(下)
leetcode-1200:最小绝对差
LeetCode 0108.将有序数组转换为二叉搜索树 - 数组中值为根,中值左右分别为左右子树
[cloud native] record of feign custom configuration of microservices
Liunx starts redis
[practical skills] how to do a good job in technical training?
Typical use cases for knapsacks, queues, and stacks
Multi screen computer screenshots will cut off multiple screens, not only the current screen
全排列的代码 (递归写法)
wordpress切换页面,域名变回了IP地址
【Rust 笔记】16-输入与输出(下)
Personal developed penetration testing tool Satania v1.2 update
Analysis of backdoor vulnerability in remote code execution penetration test / / phpstudy of national game title of national secondary vocational network security B module
1041 Be Unique
QQ computer version cancels escape character input expression
1039 Course List for Student
MatrixDB v4.5.0 重磅发布,全新推出 MARS2 存储引擎!
One question per day 2047 Number of valid words in the sentence
Implement an iterative stack
MIT-6874-Deep Learning in the Life Sciences Week 7