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. 防止点击asp.net的button按钮刷新页面(保留button的外观)

    原文发布时间为:2008-08-06 -- 来源于本人的百度文章 [由搬家工具导入] Button btn=new Button(); 1、如果用 btn.Enabled=false;是可以防止刷新的 ...

  2. 算法 & 数据结构——任意多边形填充

    需求 . 在计算机中,选区是一个很常见的功能,例如windows按住鼠标左键拖动划出矩形选区,Photshop通过钢笔工具任意形状选区.选区本身不过是通过线段闭合的一个几何形状,但是如何填充这个选区, ...

  3. EXT.JS以下两种写法在初始载入时是一样的效果

    /* Ext.application({ name: 'MyfirstApplication', launch: function () { Ext.Msg.alert("Hello&quo ...

  4. AC日记——[CQOI2014]危桥 洛谷 P3163

    题目描述 Alice和Bob居住在一个由N座岛屿组成的国家,岛屿被编号为0到N-1.某些岛屿之间有桥相连,桥上的道路是双向的,但一次只能供一人通行.其中一些桥由于年久失修成为危桥,最多只能通行两次.A ...

  5. 最简单的window下使用Jenkins来做自动化部署的教程

    今天我们来说一下,如何使用Jenkins+powershell脚本,将我们的.NET CORE的脚本部署到对应的服务器上. 这里我们使用的源码管理工具是TFS.虽然源码管理器比较老旧,但是原理都差不多 ...

  6. SRM1154--Topcoder初体验

    SRM 711 DIV2 <br > 在frank_c1的帮助下,辣鸡Xiejiadong也开始做Topcoder辣...... <br > 这算是一次Topcoder的初体验 ...

  7. Java开发笔记(一百零二)信号量的请求与释放

    前面介绍了同步与加锁两种并发处理机制,虽然加锁比起同步要灵活一些,但是加锁在某些高级场合依然力有未逮,包括但不限于下列几点:1.某块代码被加锁之后,对其它线程而言就处于繁忙状态,缺乏弹性的阈值范围:2 ...

  8. Netty----start

    一直欠着netty的帐,这次开始换上,netty 开始,学习的话,直接搞个源码的例子   http://central.maven.org/maven2/io/netty/netty-example/ ...

  9. CEF General Usage(CEF3预览)

    CEF General Usage(CEF3预览) 介绍 CEF全称Chromium Embedded Framework,是一个基于Google Chromium 的开源项目.Google Chro ...

  10. Java过滤HTML标签工具类

    过滤HTML标签能有效的放置XSS攻击. 封装: import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springf ...