[leetcode]Valid Palindrome
2013-04-28 18:53
183 查看
Given a string, determine if it is a palindrome, considering only alphanumeric characters and ignoring cases.
For example,
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.
明天就是五一小长假了,突然有点失落呀,每次放假都有点囧~~ 这是一个非常非常无聊的题,符合现在的心情,所以就写写了。。。
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) { // Start typing your C/C++ solution below // DO NOT write int main() function int p=0, q=s.size()-1; while(p<q){ if(!((s[p] >= 'a' && s[p] <= 'z') || (s[p] >= 'A' && s[p] <= 'Z') ||(s[p] - '0' >= 0 && s[p] -'0'<=9))) { p++; continue; } if(!((s[q] >= 'a' && s[q] <= 'z') || (s[q] >= 'A' && s[q] <= 'Z') ||(s[q] - '0' >= 0 && s[q] -'0'<=9))) { q--; continue; } if(s[p]!=s[q] && s[p]-s[q] != 'A'-'a' && s[p]-s[q] != 'a'-'A') return false; p++; q--; } return true; } };
相关文章推荐
- Leetcode::pow
- [leetcode]Triangle
- 【LeetCode】Binary Tree Postorder Traversal 二叉树后序遍历递归以及非递归算法
- LeetCode 76. Minimum Window Substring
- LeetCode刷题笔录Length of Last Word
- Leetcode-Missing Ranges
- [LeetCode]Convert Sorted List to Binary Search Tree
- Surrounded Regions--LeetCode
- leetcode_69题——Sqrt(x)(二分查找,还有个溢出问题的研究)
- leetcode 日经贴,Cpp code -Sliding Window Maximum
- (leetcode)Product of Array Except Self
- Remove Nth Node From End of List - Leetcode
- [LeetCode202]Happy Number判断一个数是不是happy number
- Leetcode 328:Odd Even Linked List
- [LeetCode] Trips and Users 旅行和用户
- LeetCode 172. Factorial Trailing Zeroes(0结尾)
- leetcode_c++:链表:Intersection of Two Linked Lists(160)
- LeetCode226. Invert Binary Tree
- LeetCode 423. Reconstruct Original Digits from English
- LeetCode Remove Element