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,最多可以删除一个字符. 判断它是否是回 ...
随机推荐
- charles 抓包工具破解方法
在线破解地址: https://www.zzzmode.com/mytools/charles/ 之后将下载的jar包替换 charles.app ->右键显示包内容 ->content ...
- mysql的简单介绍
一 数据类型 分为数值类型,日期时间类型,字符串类型 菜鸟教程网址:http://www.runoob.com/mysql/mysql-data-types.html
- python语言基础问题汇总
问题汇总 问题分类 怎么在一个python脚本里调用另一个python脚本 把两个脚本filea.py 和 fileb.py 放在同一个目录下,然后在filea.py的开头写: import file ...
- 旅行问题(bzoj 2746)
Description yz是Z国的领导人,他规定每个地区的名字只能为26个小写拉丁字母的一个.由于地 区数有可能超过26个,便产生了一个问题,如何辨别名字相同的地区?于是yz规定,一个 地区的描述必 ...
- 病毒(bzoj 2938)
Description 二进制病毒审查委员会最近发现了如下的规律:某些确定的二进制串是病毒的代码.如果某段代码中不存在任何一段病毒代码,那么我们就称这段代码是安全的.现在委员会已经找出了所有的病毒代码 ...
- P2330 05四川 繁忙的都市
题目描述 城市C是一个非常繁忙的大都市,城市中的道路十分的拥挤,于是市长决定对其中的道路进行改造.城市C的道路是这样分布的:城市中有n个交叉路口,有些交叉路口之间有道路相连,两个交叉路口之间最多有一条 ...
- scroll与按钮的位置
<!doctype html> <html lang="en"> <head> <meta charset="UTF-8&quo ...
- springboot整合mybatis(SSM开发环境搭建)
0.项目结构: ---------------------方法一:使用mybatis官方提供的Spring Boot整合包实现--------------------- 1.application.p ...
- 深入了解Entity Framework框架及访问数据的几种方式
一.前言 1.Entity Framework概要 Entity Framework是微软以ADO.NET为基础所发展出来的对象关系映射(O/R Mapping)解决方案.该框架曾经为.NET Fra ...
- CSS-文本(中,英)
1.缩进文本:text-indent 2.水平对齐:text-align: left/center/right/justify(实现两端对齐文本效果) 3.字间隔:word-spacing(可以改变 ...