leetcode26:valid-palindrome
2024-09-05 11:32:28
题目描述
判断题目给出的字符串是不是回文,仅考虑字符串中的字母字符和数字字符,并且忽略大小写
例如:"A man, a plan, a canal: Panama"是回文
"race a car"不是回文
注意:
你有没有考虑过字符串可能为空?这是面试时应该提出的一个好问题。
针对这个问题,我们定义空字符串是回文
Given a string, determine if it is a palindrome, considering only alphanumeric characters and ignoring cases.
For example,
"A man, a plan, a canal: Panama"is a palindrome.
"race a car"is not a palindrome.
Note:
Have you consider that the string might be empty? This is a good question to ask during an interview.
For the purpose of this problem, we define empty string as valid palindrome.
示例2
输出
class Solution {
public:
/**
*
* @param s string字符串
* @return bool布尔型
*/
bool isPalindrome(string s) {
int i,j;
for(i=0,j=s.length()-1;i<j;++i,--j){
while(i<j && !isalnum(s[i])) ++i;
while(i<j && !isalnum(s[j])) --j;
if (i<j && tolower(s[i])!=tolower(s[j])) return false;
}
return true;
}
};
最新文章
- 在Heroku部署时,无法加载 css,js,图片资源解决办法
- [Python]logging模块使用basicConfig后记录日志重复问题
- java 代码如何生成 chm
- linux/shell sort命令
- vs2013搭建团队版本控制 TFS、SVN
- hdu Hat&#39;s Tea
- 关于wkwebview
- jQuery系列 第四章 jQuery框架的选择器
- 和逛微博、刷朋友圈一样玩转 GitHub
- 【linux日常】 ACL权限管理
- Flutter - Migrate to AndroidX
- mysql安装5.7.20版本
- python学习 day13 迭代器,生成器,枚举对象
- 【九天教您南方cass 9.1】 03 编码法绘制地形图
- MySQL操作数据库--与MySQL零距离接触1-7
- linux动态追踪神器——Strace实例介绍【转】
- 《Erlang程序设计(第2版)》
- python基础学习1-函数相关
- javascript 内置类型
- Mysql 知识点总结