125. Valid Palindrome

来源:互联网 发布:开淘宝店怎么代理货源 编辑:程序博客网 时间:2024/06/05 18:30

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.

Subscribe to see which companies asked this question

class Solution {public:    bool isPalindrome(string s) {        string temp="";        for(int i=0;i<s.size();++i)        {            if((s[i]>='a')&&(s[i]<='z')||(s[i]>='A')&&(s[i]<='Z')||(s[i]>='0')&&(s[i]<='9'))            {                if((s[i]>='A')&&(s[i]<='Z'))                {                    temp+=('z'-('Z'-s[i]));                }                else                temp+=s[i];            }        }        return temp==string(temp.rbegin(),temp.rend());    }};

0 0
原创粉丝点击