当前位置:网站首页>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;
}
};
边栏推荐
- leetcode-31:下一个排列
- 【Rust 笔记】17-并发(上)
- Appium基础 — 使用Appium的第一个Demo
- [rust notes] 17 concurrent (Part 1)
- Convolution neural network -- convolution layer
- MIT-6874-Deep Learning in the Life Sciences Week 7
- 中职网络安全技能竞赛——广西区赛中间件渗透测试教程文章
- 2022年贵州省职业院校技能大赛中职组网络安全赛项规程
- Introduction to LVS [unfinished (semi-finished products)]
- Is it impossible for lamda to wake up?
猜你喜欢
Real time clock (RTC)
Appium automation test foundation - Summary of appium test environment construction
Dichotomy, discretization, etc
wordpress切换页面,域名变回了IP地址
Solution to game 10 of the personal field
CCPC Weihai 2021m eight hundred and ten thousand nine hundred and seventy-five
Matrixdb V4.5.0 was launched with a new mars2 storage engine!
Personal developed penetration testing tool Satania v1.2 update
Navicat连接Oracle数据库报错ORA-28547或ORA-03135
Wazuh开源主机安全解决方案的简介与使用体验
随机推荐
【Rust 笔记】14-集合(上)
1041 Be Unique
[rust notes] 16 input and output (Part 1)
884. Uncommon words in two sentences
[practical skills] technical management of managers with non-technical background
On the characteristics of technology entrepreneurs from Dijkstra's Turing Award speech
Personal developed penetration testing tool Satania v1.2 update
从Dijkstra的图灵奖演讲论科技创业者特点
Some common problems in the assessment of network engineers: WLAN, BGP, switch
One question per day 1447 Simplest fraction
How to adjust bugs in general projects ----- take you through the whole process by hand
Appium automation test foundation - Summary of appium test environment construction
2017 USP Try-outs C. Coprimes
In depth analysis of for (VaR I = 0; I < 5; i++) {settimeout (() => console.log (I), 1000)}
智慧工地“水电能耗在线监测系统”
【Rust 笔记】17-并发(下)
1.14 - 流水线
1040 Longest Symmetric String
[jailhouse article] jailhouse hypervisor
Over fitting and regularization