当前位置:网站首页>Leetcode 125. 验证回文串
Leetcode 125. 验证回文串
2022-07-30 11:02:00 【我不是萧海哇~~~~】
给定一个字符串,验证它是否是回文串,只考虑字母和数字字符,可以忽略字母的大小写。
说明:本题中,我们将空字符串定义为有效的回文串。
示例 1:
输入: "A man, a plan, a canal: Panama"
输出: true
解释:"amanaplanacanalpanama" 是回文串
示例 2:
输入: "race a car"
输出: false
解释:"raceacar" 不是回文串
提示:
- 1 <= s.length <= 2 * 10^5
- 字符串 s 由 ASCII 字符组成
Code:
class Solution {
public:
bool isPalindrome(string s) {
if(s.length()==0)
return true;
std::transform(s.begin(), s.end(), s.begin(), ::tolower);
string res;
for(int i=0;i<(int)s.length();i++)
{
if(s[i]>='a'&&s[i]<='z')
{
res+=s[i];
}
if(s[i]>='A'&&s[i]<='Z')
{
res+=s[i];
}
if(s[i]>='0'&&s[i]<='9')
{
res+=s[i];
}
}
if(res.length()==0)
return true;
cout<<res<<endl;
for(int i=0;i<=(int)res.length()/2;i++)
{
if(res[i]!=res[res.length()-i-1])
return false;
}
return true;
}
};
边栏推荐
- MySQL之数据库维护
- Scrapy crawler website image crawling
- Verilog之数码管译码
- [HarmonyOS] [ARK UI] How to double-click the return key to exit in HarmonyOS ets language
- Neural Network Study Notes 4 - Autoencoder (including sparse, stacked) (updated)
- Vim plugin GrepIt
- 美团内推+校招笔试题+知识点总结
- PL5920 SOT-23-6 21V、2A、600KHz同步降压DC/DC转换器
- log4j Logger简介说明
- xshell使用技巧(赚分享平台怎么样)
猜你喜欢
随机推荐
Neural Ordinary Differential Equations
xshell使用技巧(赚分享平台怎么样)
unity3d C#语言基础(继承)
WEB3之路(一)-- solidity学习笔记
MySQL database maintenance
IP池设计思考(面试点)[通俗易懂]
淘宝/天猫淘宝评论问答列表接口 API
【梦想起航】
RandLA-Net复现记录
深入浅出零钱兑换问题——背包问题的套壳
Typroa alternative tool marktext
TensorFlow自定义训练函数
Drag and drop events, dataTransfer, getBoundingClientRect
鸿湖万联扬帆富设备开发板正式合入OpenHarmony主干
【JZ64 求1+2+3+...+n】
安全提示:Qt中的FreeType
面试官:Redis中的布隆过滤器与布谷鸟过滤器,你了解多少?
RY-D1/1 Voltage Relay
Verilog之数码管译码
Scrapy crawler website image crawling