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.
 
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.

  

复制代码
class Solution {
public:
    bool  check(char test, char & c)
    {
       if(test >= 'a' && test <= 'z')
       {
        c = test;
        return true;
       }else if(test >= 'A' && test <= 'Z'){
     
        c = test - 'A' + 'a';
        return true;
       }else if (test >= '0' && test <= '9'){
     
          c = test;
          return true;
       }
       return false;
    }
    bool isPalindrome(string s) {
        // Start typing your C/C++ solution below
        // DO NOT write int main() function
        int j = s.length();
        if(j-- == 0) return true;
        int i = 0; char head,tail;
        while(i<j){
            while(i<j){
                if(check(s[i],head)) break;
                i++;
            }
            if(i>=j) return true;
            
            while(i<j){
                if(check(s[j], tail)) break;
                j--;
            }
            if(i>=j) return true;
            if(head != tail ) return false;
            i++;j--;
        }
        return true ;
    }
};
复制代码

 

posted @   冰点猎手  阅读(200)  评论(0编辑  收藏  举报
编辑推荐:
· Java 中堆内存和栈内存上的数据分布和特点
· 开发中对象命名的一点思考
· .NET Core内存结构体系(Windows环境)底层原理浅谈
· C# 深度学习:对抗生成网络(GAN)训练头像生成模型
· .NET 适配 HarmonyOS 进展
阅读排行:
· 本地部署 DeepSeek:小白也能轻松搞定!
· 如何给本地部署的DeepSeek投喂数据,让他更懂你
· 从 Windows Forms 到微服务的经验教训
· 李飞飞的50美金比肩DeepSeek把CEO忽悠瘸了,倒霉的却是程序员
· 超详细,DeepSeek 接入PyCharm实现AI编程!(支持本地部署DeepSeek及官方Dee
点击右上角即可分享
微信分享提示