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 isPalindrome(string s) {
int left= , right = s.length()-;
while(left <= right){
while(left<=right && !isalnum(s[left])) left++;
while(left<=right && !isalnum(s[right])) right--;
if(left > right) break;
if(isalpha(s[left]) && isalpha(s[right]) && tolower(s[left]) == tolower(s[right])){
left++;
right--;
}
else if(isdigit(s[left])&& isdigit(s[right]) && s[left] == s[right]){
left++;
right--;
}
else break;
}
if(left <= right) return false;
else return true;
}
};

Leetcode Valid Palindrome的更多相关文章

  1. [LeetCode] Valid Palindrome 验证回文字符串

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

  2. LeetCode——Valid Palindrome

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

  3. [LeetCode] Valid Palindrome II 验证回文字符串之二

    Given a non-empty string s, you may delete at most one character. Judge whether you can make it a pa ...

  4. [leetcode]Valid Palindrome @ Python

    原题地址:https://oj.leetcode.com/problems/valid-palindrome/ 题意: Given a string, determine if it is a pal ...

  5. LeetCode Valid Palindrome II

    原题链接在这里:https://leetcode.com/problems/valid-palindrome-ii/description/ 题目: Given a non-empty string  ...

  6. LeetCode: Valid Palindrome [125]

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

  7. LeetCode: Valid Palindrome 解题报告

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

  8. [Leetcode] valid palindrome 验证回文

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

  9. leetcode Valid Palindrome C++&amp;python 题解

    题目描写叙述 Given a string, determine if it is a palindrome, considering only alphanumeric characters and ...

随机推荐

  1. OpenGL Common Mistakes

    https://www.opengl.org/wiki/Common_Mistakes Do not use constructors/destructors to initialize/destro ...

  2. [NHibernate]缓存(NHibernate.Caches)

    系列文章 [Nhibernate]体系结构 [NHibernate]ISessionFactory配置 [NHibernate]持久化类(Persistent Classes) [NHibernate ...

  3. 【09-14】eclipse学习笔记

    eclipse安装class文件反编译插件jadClipse /** 1. 下载JadClipse的jar包 2. 下载Jad反编译器 3. 将JarClipse jar包放到eclipse plug ...

  4. ThinkPHP真正疑难问题笔记

    如何选择线程安全版本还是非线程安全版本: http://www.cnblogs.com/Alight/p/3389113.html(看webserver处理请求时, 使用的是多线程的方式还是 多进程的 ...

  5. $_SERVER 的用法

    PHP编程中经常需要用到一些服务器的一些资料,特把$_SERVER的详细参数整理下,方便以后使用. $_SERVER['PHP_SELF'] #当前正在执行脚本的文件名,与 document root ...

  6. MySQL show processlist命令详解

    show processlist; 命令的输出结果显示了有哪些线程在运行,可以帮助识别出有问题的查询语句,两种方式使用这个命令. 方式1:进入mysql/bin目录下输入mysqladmin proc ...

  7. fetch 资源请求

    简介:fetch() 方法用于发起获取资源的请求.它返回一个 promise,这个 promise 会在请求响应后被 resolve,并传回 Response 对象. 为了更好的体验,可点击这里阅读 ...

  8. GET和POST可传递的值到底有多大?

    前日,看到这个问题了. 没有深入了解.我的常识里面get最大传递的值为256b,post 是2M.这是很久以前不知在哪看到的.于是又百度一下.看到两篇文章装过来看看: 浅谈 HTTP中Get与Post ...

  9. java程序打包成jar

    1. 建立文件夹:proj,在该文件夹下建立3个子文件夹:lib,src 2. 在lib文件夹中放置依赖的jar包 3. 在src中放置类文件:com.cnjava.demo.Main.java 4. ...

  10. poj 3468(线段树)

    http://poj.org/problem?id=3468 题意:给n个数字,从A1 …………An m次命令,Q是查询,查询a到b的区间和,c是更新,从a到b每个值都增加x.思路:这是一个很明显的线 ...