博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
leetcode[125]Valid Palindrome
阅读量:4512 次
发布时间:2019-06-08

本文共 1229 字,大约阅读时间需要 4 分钟。

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 isValid(char c){    if((c>='a'&&c<='z')||(c>='A'&&c<='Z')||(c>='0'&&c<='9'))return true;    return false;}bool isSame(char c1, char c2){    if(c1>='0'&&c1<='9')return c1==c2;    if((c1>='A'&&c1<='Z'))return (c1==c2)||(c1==c2-32);    if(c1>='a'&&c1<='z')return (c1==c2)||(c1==c2+32);}    bool isPalindrome(string s) {        if(s.empty()||s.size()==1)return true;        int n=s.size();        int i=0,j=n-1;        for(;i
=0&&i<=j;) {// if(i==j)return true; while(!isValid(s[i]))i++; while(!isValid(s[j]))j--; if(i==j||i>j)return true; if(!isSame(s[i],s[j]))return false; i++; j--; } if(i==j||i>j)return true; return false; }};

 

转载于:https://www.cnblogs.com/Vae1990Silence/p/4281274.html

你可能感兴趣的文章
【Lucene】Apache Lucene全文检索引擎架构之中文分词和高亮显示4
查看>>
「SDOI2018」物理实验
查看>>
160620、利用 jQuery UI 和 Ajax 创建可定制的 Web 界面
查看>>
基线 css
查看>>
100_remove-duplicates-from-sorted-array
查看>>
数据库表新增触发器
查看>>
Spring源码情操陶冶-AbstractApplicationContext#initApplicationEventMulticaster
查看>>
Maven
查看>>
Oracle 函数大全
查看>>
UVa 10791 - Minimum Sum LCM 质因数分解加素数筛优化
查看>>
Microsoft Excel 准确按照一页的宽度和高度打印
查看>>
React Router 使用教程
查看>>
Swift-函数
查看>>
闲聊CSS之关于clearfix--清除浮动[转]
查看>>
生成实体文件 需要用到的SQL 语句
查看>>
Java迭代实现斐波那契数列
查看>>
Application+Handle+Task
查看>>
69道Spring面试题和答案
查看>>
FastCopy总结
查看>>
systeminfo总结
查看>>