标签:
题目描述:(链接)
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 class Solution { 2 public: 3 bool isPalindrome(string s) { 4 int len = s.size(); 5 if (len <= 1) { 6 return true; 7 } 8 9 int start = 0; 10 int last = len - 1; 11 while (start <= last) { 12 while (start <=last && !isalnum(s[start])) { ++start; } 13 while (start <= last && !isalnum(s[last])) { -- last; } 14 15 if (start <= last && tolower(s[start]) != tolower(s[last])) { 16 return false; 17 } 18 19 ++start; 20 --last; 21 } 22 23 return true; 24 } 25 };
标签:
原文地址:http://www.cnblogs.com/skycore/p/4951623.html