【LeetCode】125. Valid Palindrome

题目:

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.

提示:

比较简单的题目,要注意下面三点即可:

  • 忽略大小写
  • 只考虑数字和英文字母
  • 空字符串符合要求

代码:

class Solution {
public:
bool isPalindrome(string s) {
if (s.size() == ) return true;
for (int i = , j = s.size() - ; i < j; ++i, --j) {
while (!isalnum(s[i]) && i < s.size()) ++i;
while (!isalnum(s[j]) && j > ) --j;
if (tolower(s[i]) != tolower(s[j]) && i < j) return false;
}
return true;
}
};
上一篇:腾讯X5内核使用详解(X5内核播放器使用如何去除控制栏全屏播放)以及一些注意事项


下一篇:h5自定义播放器得实现原理