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的更多相关文章

  1. [LeetCode 题解]: Valid Palindrome

    Given a string, determine if it is a palindrome, considering only alphanumeric characters and ignori ...

  2. LeetCode(125) Valid Palindrome

    题目 Given a string, determine if it is a palindrome, considering only alphanumeric characters and ign ...

  3. 【LeetCode OJ】Valid Palindrome

    Problem Link: http://oj.leetcode.com/problems/valid-palindrome/ The following two conditions would s ...

  4. 【LeetCode练习题】Valid Palindrome

    Valid Palindrome Given a string, determine if it is a palindrome, considering only alphanumeric char ...

  5. LeetCode OJ:Valid Palindrome(验证回文)

    Valid Palindrome Given a string, determine if it is a palindrome, considering only alphanumeric char ...

  6. LeetCode算法题-Valid Palindrome(Java实现)

    这是悦乐书的第174次更新,第176篇原创 01 看题和准备 今天介绍的是LeetCode算法题中Easy级别的第33题(顺位题号是125).给定一个字符串,确定它是否是回文,只考虑字母数字字符并忽略 ...

  7. 【LeetCode】680. Valid Palindrome II

    Difficulty:easy  More:[目录]LeetCode Java实现 Description https://leetcode.com/problems/valid-palindrome ...

  8. 【LeetCode】680. Valid Palindrome II 验证回文字符串 Ⅱ(Python)

    作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 双指针 思路来源 初版方案 进阶方案 日期 题目地址 ...

  9. LeetCode算法题-Valid Palindrome II(Java实现)

    这是悦乐书的第287次更新,第304篇原创 01 看题和准备 今天介绍的是LeetCode算法题中Easy级别的第155题(顺位题号是680).给定非空字符串s,最多可以删除一个字符. 判断它是否是回 ...

随机推荐

  1. 2017.8.1 Noip2018模拟测试赛(十七)

    日期: 八月第一天  总分: 300分  难度: 提高 ~ 省选    得分: 100分(不应该啊!) 题目目录: T1:战争调度 T2:选数 T3:由乃的OJ 赛后心得: MMP,首先第一题花了大概 ...

  2. RGB和YUV之比较【转】

    转自:http://blog.csdn.net/qfnu08zzr/article/details/6763159 版权声明:本文为博主原创文章,未经博主允许不得转载. RGB 原理 RGB 是从颜色 ...

  3. Android 禁止状态栏下拉status bar

    如果你有这样的需求:用户进入你的app以后,所有的操作都是你的app中设定的,用户不可以拥有系统设置等行为的能力.然而,Android系统,可以通过从顶部往下拉,从而得到一个通知和快速系统设置的页面: ...

  4. poj 3281(构图+网络流)

    Dining Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 14144   Accepted: 6425 Descripti ...

  5. IDEA重新打jar包时报错MANIFEST.MF already exists in VFS

    报错原因:曾经打过jar包了,把之前的包删掉无用,VFS:虚拟文件系统.即使删掉之前的包,信息依然会在此处.故删掉MANIFEST文件夹,重新打包即可解决.

  6. (2)Unity3d菜单

    1.文件菜单 2.编辑菜单 Frame Selected 焦点选择和双击Hierarchy中的元素一样的功能 Lock View to Selected  选中对象再点击此按钮,在场景视图中移动此对象 ...

  7. Codeforces 553D Nudist Beach(二分答案 + BFS)

    题目链接 Nudist Beach 来源  Codeforces Round #309 (Div. 1) Problem D 题目大意: 给定一篇森林(共$n$个点),你可以在$n$个点中选择若干个构 ...

  8. Java创建和解析Json数据方法(四)——json-lib包的使用

    (四)json-lib包的使用         既然json-lib包比org.json包重量级,那么json-lib包肯定有很多org.json包没有的类和方法,这篇笔记简单记录json-lib包中 ...

  9. iOS Mobile Development: Using Xcode Targets to Reuse the Code 使用xcode targets来实现代码复用

    In the context of iOS mobile app development, a clone is simply an app that is based off another mob ...

  10. xamarin studio 安装

    公司wpf项目移植到mac,用到mono来进行重写,不会,自己开搞 首先一个问题Xamarin怎么读,xaml熟悉吧,xaml读作Zamel,xamarin也就读作Zamerin,恩,就是它了... ...