验证回文串
题目要求

 示例 1:
输入: s = “A man, a plan, a canal: Panama”
 输出:true
 解释:“amanaplanacanalpanama” 是回文串。
 示例 2:
输入:s = “race a car”
 输出:false
 解释:“raceacar” 不是回文串。
 示例 3:
输入:s = " "
 输出:true
 解释:在移除非字母数字字符之后,s 是一个空字符串 “” 。
 由于空字符串正着反着读都一样,所以是回文串。
提示:
- 1 <= s.length <= 2 * 105
 - s 仅由可打印的 ASCII 字符组成
 
解题思路
1.遍历s,将其中的大小写字符和数字保存到s1中,并且,将大写英文转换成小写。
 2.使用前后指针left和right。向中间遍历,如果有不同的就返回错误。
难点:英文大小写转换方法:
- 1.使用Ascll码。
【小写 - 32 =大写】 ————【大写 + 32 = 小写】 - 2.使用函数
tolower();将大写字母转换为小写字母
toupper();将小写字母转换为大写字母 
这两个函数只会对英文字母产生作用,如果取到其他类型例如数字,会不做处理。
C++代码
class Solution {
public:
    bool isPalindrome(string s) {
        string s1;
        if(s.size()==0) return true;
        for (auto ch : s)
        {
            if ((ch >= 'a' && ch<= 'z') || (ch >= 'A' && ch <= 'Z') || (ch >= '0' && ch <= '9'))
            {
                if (ch >= 'A' && ch <= 'Z')
                {
                ch +=  32;
                }
            s1 += ch;
            }
        }
   
        int left =0,right = s1.size()-1;
        while(left<right)
        {
            if(s1[left]!=s1[right])
            {
                return false;
            }
            ++left;
            --right;
        }
        return true;
    }
};
 
使用大小写转换函数
class Solution {
public:
    bool isPalindrome(string s) {
        string s1;
        if(s.size()==0) return true;
        for (auto ch : s)
        {
            if ((ch >= 'a' && ch<= 'z') || (ch >= 'A' && ch <= 'Z') || (ch >= '0' && ch <= '9'))
            {
            s1 += ch;
            }
        }
        int left =0,right = s1.size()-1;
        while(left<right)
        {
            if(tolower(s1[left])!=tolower(s1[right]))
            {
                return false;
            }
            ++left;
            --right;
        }
        return true;
    }
};
                
















