125. Valid Palindrome

来源:互联网 发布:淘宝卖家买家一个账号 编辑:程序博客网 时间:2024/06/16 18:24

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.

class Solution 

{
public:
    bool isPalindrome(string s) 

   {

          int left;

         int right;

           left=0;

           right=s.size()-1;

        while(left<=right)

          {

                while(left<right&&isalnum(s[left])==0)

                    left++;

                

              while(left<right&&isalnum(s[right])==0)

                    right--;

               if(toupper(s[left]) != toupper(s[right]))

                    return false;

                  left++;

                  right--;

           }

              return true;

   }

};

原创粉丝点击