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 ; } };
--------------------------------------------------------------------天道酬勤!
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】凌霞软件回馈社区,博客园 & 1Panel & Halo 联合会员上线
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】博客园社区专享云产品让利特惠,阿里云新客6.5折上折
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· Java 中堆内存和栈内存上的数据分布和特点
· 开发中对象命名的一点思考
· .NET Core内存结构体系(Windows环境)底层原理浅谈
· C# 深度学习:对抗生成网络(GAN)训练头像生成模型
· .NET 适配 HarmonyOS 进展
· 本地部署 DeepSeek:小白也能轻松搞定!
· 如何给本地部署的DeepSeek投喂数据,让他更懂你
· 从 Windows Forms 到微服务的经验教训
· 李飞飞的50美金比肩DeepSeek把CEO忽悠瘸了,倒霉的却是程序员
· 超详细,DeepSeek 接入PyCharm实现AI编程!(支持本地部署DeepSeek及官方Dee