当前位置:网站首页>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;
}
};
边栏推荐
- Liunx starts redis
- Data visualization chart summary (II)
- [jailhouse article] look mum, no VM exits
- 从Dijkstra的图灵奖演讲论科技创业者特点
- 数据可视化图表总结(二)
- 对for(var i = 0;i < 5;i++) {setTimeout(() => console.log(i),1000)}的深入分析
- LeetCode 0107.二叉树的层序遍历II - 另一种方法
- Collection: programming related websites and books
- Fried chicken nuggets and fifa22
- One question per day 1765 The highest point in the map
猜你喜欢
Arduino 控制的 RGB LED 无限镜
[jailhouse article] look mum, no VM exits
实时时钟 (RTC)
LeetCode 0108.将有序数组转换为二叉搜索树 - 数组中值为根,中值左右分别为左右子树
Time of process
In this indifferent world, light crying
Data visualization chart summary (II)
Error ora-28547 or ora-03135 when Navicat connects to Oracle Database
Matrixdb V4.5.0 was launched with a new mars2 storage engine!
QQ computer version cancels escape character input expression
随机推荐
QQ computer version cancels escape character input expression
884. Uncommon words in two sentences
A reason that is easy to be ignored when the printer is offline
【实战技能】如何做好技术培训?
Redis publish subscribe command line implementation
MIT-6874-Deep Learning in the Life Sciences Week 7
2022 pole technology communication arm virtual hardware accelerates the development of Internet of things software
Erreur de connexion Navicat à la base de données Oracle Ora - 28547 ou Ora - 03135
Daily question 1342 Number of operations to change the number to 0
1039 Course List for Student
1996. number of weak characters in the game
Simply sort out the types of sockets
CF1634E Fair Share
leetcode-22:括号生成
1040 Longest Symmetric String
Introduction et expérience de wazuh open source host Security Solution
QQ电脑版取消转义符输入表情
做 SQL 性能优化真是让人干瞪眼
Matrixdb V4.5.0 was launched with a new mars2 storage engine!
Collection: programming related websites and books