LeetCode(125)题解--Valid Palindrome
https://leetcode.com/problems/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.
思路:
easy.
AC代码:
class Solution {
public:
bool isPalindrome(string s) {
int a=,b=s.size()-;
while(a<b){
if(!((s[a]>='a'&&s[a]<='z')||(s[a]>='A'&&s[a]<='Z')||(s[a]>=''&&s[a]<=''))){
a++;
continue;
}
if(!((s[b]>='a'&&s[b]<='z')||(s[b]>='A'&&s[b]<='Z')||(s[b]>=''&&s[b]<=''))){
b--;
continue;
}
if((s[a]>='a'&&s[a]<='z')){
if((s[a]!=s[b])&&(s[a]+'A'-'a'!=s[b])){
return false;
}
}
else if((s[a]>='A'&&s[a]<='Z')){
if((s[a]!=s[b])&&(s[a]!=s[b]+'A'-'a')){
return false;
}
}
else{
if(s[a]!=s[b]){
return false;
}
}
a++;
b--;
}
return true;
}
};
LeetCode(125)题解--Valid Palindrome的更多相关文章
- [LeetCode 题解]: Valid Palindrome
Given a string, determine if it is a palindrome, considering only alphanumeric characters and ignori ...
- LeetCode(125) Valid Palindrome
题目 Given a string, determine if it is a palindrome, considering only alphanumeric characters and ign ...
- 【LeetCode OJ】Valid Palindrome
Problem Link: http://oj.leetcode.com/problems/valid-palindrome/ The following two conditions would s ...
- 【LeetCode练习题】Valid Palindrome
Valid Palindrome Given a string, determine if it is a palindrome, considering only alphanumeric char ...
- LeetCode OJ:Valid Palindrome(验证回文)
Valid Palindrome Given a string, determine if it is a palindrome, considering only alphanumeric char ...
- LeetCode算法题-Valid Palindrome(Java实现)
这是悦乐书的第174次更新,第176篇原创 01 看题和准备 今天介绍的是LeetCode算法题中Easy级别的第33题(顺位题号是125).给定一个字符串,确定它是否是回文,只考虑字母数字字符并忽略 ...
- 【LeetCode】680. Valid Palindrome II
Difficulty:easy More:[目录]LeetCode Java实现 Description https://leetcode.com/problems/valid-palindrome ...
- 【LeetCode】680. Valid Palindrome II 验证回文字符串 Ⅱ(Python)
作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 双指针 思路来源 初版方案 进阶方案 日期 题目地址 ...
- LeetCode算法题-Valid Palindrome II(Java实现)
这是悦乐书的第287次更新,第304篇原创 01 看题和准备 今天介绍的是LeetCode算法题中Easy级别的第155题(顺位题号是680).给定非空字符串s,最多可以删除一个字符. 判断它是否是回 ...
随机推荐
- UVa11542 Square
/*by SilverN*/ #include<iostream> #include<algorithm> #include<cstring> #include&l ...
- [LeetCode] Rotate Image n-by-n矩阵顺时针旋转
You are given an n x n 2D matrix representing an image. Rotate the image by 90 degrees (clockwise). ...
- java中线程切换的开销
思路: 开三个线程A,B,C 线程A不断的调用LockSupport.park()阻塞自己,一旦发现自己被唤醒,调用Thread.interrupted()清除interrupt标记位,同时增加自增计 ...
- 洛谷——P1508 Likecloud-吃、吃、吃
P1508 Likecloud-吃.吃.吃 题目背景 问世间,青春期为何物? 答曰:“甲亢,甲亢,再甲亢:挨饿,挨饿,再挨饿!” 题目描述 正处在某一特定时期之中的李大水牛由于消化系统比较发达,最近一 ...
- Leetcode总结之Backtracking
本文我们就Leetcode中的一个类型的题目backtracking进行一系列的总结和归纳.backtracking这个方法本质是建立在递归的基础上,不断尝试新的路径,这里关键是每次尝试完以后需要退回 ...
- sed命令2
测试文件sedtest.txt,内容为: [root@localhost sed]# cat sedtest.txt my cat's name is betty it's a cat; this i ...
- ios 联网 在mac机器上进行抓包
Remote Virtual Interface在使用Mac抓取iPhone数据包中介绍了两种方式在Mac电脑上抓取iPhone上的数据包,一是使用Mac的网络共享功能将Mac的网络通过WiFi共享给 ...
- 【MyEcplise】设置右键快捷菜单的方法
在我们右键新建项目或文件时,有许多的选项我们几乎是不用的,那就没有必要放在右键的快捷菜单中:而有些选项是我们经常会用的,但是右键快捷菜单有没有,我们总是需要选择其它去到弹出的对话框中取选取.这些操作很 ...
- [MFC]选择目录对话框和选择文件对话框 [转]
在MFC编程中经常会需要用到选择目录和选择文件的界面,以下总结一下本人常用的这两种对话框的生成方法: 选择目录对话框 { char szPath[MAX_PATH]; //存放选择的 ...
- Ubuntu 安装 spark
环境: Unbunt 12.04 Hadoop 2.2.x Sprak 0.9 Scala scala-2.9.0.final.tgz 步骤 1. 下载 scala 2. 解压scala,然后改动/e ...