当前位置:网站首页>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;
}
};
边栏推荐
- Some commands of kubernetes
- Swift common extension classes and simple encapsulation
- idea的package没有空心
- WebAPI 复习
- 2022全球数字经济大会人工智能专场:AI安全受高度关注
- log4js入门
- typescript入门之helloworld
- async.js入门
- Hu-cang integrated e-commerce project (1): project background and structure introduction
- Performance testing of API Gateway APISIX on Google Cloud T2A and T2D
猜你喜欢

零代码开发入门:快速上手DIY函数公式的5个步骤

电流继电器JL-8GB/11/AC220V

RY-D1/1 Voltage Relay

ESP32CAM 1838接收红外遥控器信号

Beyond Stream Processing !第四届实时计算 Flink 挑战赛启动,49 万奖金等你来拿!
![【 HMS core 】 【 Analytics Kit] [FAQ] how to solve the payment amount in huawei pay analysis shows zero problem?](/img/f3/b9256fc04d1c9e15c74d2fc14db0fb.png)
【 HMS core 】 【 Analytics Kit] [FAQ] how to solve the payment amount in huawei pay analysis shows zero problem?

【HMS core】【FAQ】HMS Toolkit Typical Questions Collection 1

HJY-F931A/YJ三相电压继电器

RandLA-Net复现记录

物联网技术概论:第6章
随机推荐
AB test summary
鸿湖万联扬帆富设备开发板正式合入OpenHarmony主干
Vim plugin GrepIt
加密和安全
湖仓一体电商项目(一):项目背景和架构介绍
【ASP.NET Core】选项类的依赖注入
Unity 锁定相机第二弹
vscode中写markdown格式笔记的配置过程和相关语法
Neural Ordinary Differential Equations
TensorFlow自定义训练函数
Typroa 替代工具marktext
Hu-cang integrated e-commerce project (1): project background and structure introduction
Classes and Objects - 6 Default Member Functions
UE5 GAS Study Notes Postscript 0
Understanding of deadlock
Performance testing of API Gateway APISIX on Google Cloud T2A and T2D
Log4j additivity属性简介说明
ODrive应用 #4 配置参数&指令「建议收藏」
【云筑共创】华为云携手鸿蒙,端云协同,培养创新型开发者
Scrapy crawler website image crawling