首页 > 代码库 > [Leetcode]Valid Palindrome

[Leetcode]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.

 这题是看答案写出来的,解题思路就是头尾匹配再前后数组下标向中间移位1,continue在这的作用有点费解,没有的话会报错,待研究。。。

 1 class Solution { 2 public: 3     bool isValid(char c) { 4     return (c >= a && c <= z) || (c >= A && c <= Z) || (c >= 0 && c <= 9); 5 } 6 bool isPalindrome(string s) { 7     int start = 0, end = s.size() - 1; 8     while (start < end) { 9         if (!isValid(s[start])) { start ++; continue; }10         if (!isValid(s[end])) { end --; continue; }11         if (s[start] != s[end] && abs(s[start] - s[end]) != 32) return false;12         start ++;13         end --;14     }15     return true;16 }17 };

[Leetcode]Valid Palindrome