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.

Solution 1:

class Solution
{
public:
bool isPalindrome(string s)
{
int left = , right = s.length() - ;
while(left < right)
{
char a = tolower(s[left]), b = tolower(s[right]);
if(!isalnum(a))
{
++left;
continue;
}
if(!isalnum(b))
{
--right;
continue;
}
if(a != b) return false; ++left;
--right;
}
return true; }
};

Valid Palindrome ---- LeetCode 125的更多相关文章

  1. Valid Palindrome [LeetCode]

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

  2. Valid Palindrome leetcode java

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

  3. [LeetCode]题解(python):125 Valid Palindrome

    题目来源 https://leetcode.com/problems/valid-palindrome/ Given a string, determine if it is a palindrome ...

  4. 【一天一道LeetCode】#125. Valid Palindrome

    一天一道LeetCode 本系列文章已全部上传至我的github,地址:ZeeCoder's Github 欢迎大家关注我的新浪微博,我的新浪微博 欢迎转载,转载请注明出处 (一)题目 Given a ...

  5. LeetCode(125)题解--Valid Palindrome

    https://leetcode.com/problems/valid-palindrome/ 题目: Given a string, determine if it is a palindrome, ...

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

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

  7. 【LeetCode】125. Valid Palindrome 解题报告(Python & C++)

    作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 目录 题目描述 解题方法 列表生成式 正则表达式 双指针 日期 题目地址:https:/ ...

  8. leetcode 125. Valid Palindrome ----- java

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

  9. LeetCode 125. Valid Palindrome

    这个题目只要注意大小写问题即可解决,而且我们只关注的是字母和数值 Given a string, determine if it is a palindrome, considering only a ...

随机推荐

  1. 【Delphi7】 解决“程序第一次可以正常编译,但再次编译的时候会报错,必须重新打开Delphi”的问题

    报错如下: Access violation at address 00495044 in module 'coreide70.bpl'. Read of address...Access viola ...

  2. Android Studio 如何切换sdk

      选择File-->Project Structure 弹出框中选择Project 看到中间的Project SDK项. 点击Edit或者New 然后就可以选择Build target 和Ja ...

  3. Windows安装MySQL5.7.17

    1. 在MySQL官网 http://dev.mysql.com/downloads/mysql/ 上面下载ZIP安装包(第二个:Windows (x86, 64-bit), ZIP Archive) ...

  4. Notepad++进行php开发所必需的插件

    Notepad++进行php开发所必需的插件有那些呢? 1. Compare: 可以用来比较两个文件不同之处. 2. Explorer:文件浏览器插件,包含收藏夹.Session保存功能.可与NppE ...

  5. mysql数据库的导入导出

    当我们在操作数据库的时候,难免会遇到数据导入导出的一些操作,今天突然学到了这个知识点,特意来给大家分享. 我用的是data的这条数据 1.使用数据 mysql> use data; Databa ...

  6. 断言(assert)的用法

    我一直以为assert仅仅是个报错函数,事实上,它居然是个宏,并且作用并非“报错”. 在经过对其进行一定了解之后,对其作用及用法有了一定的了解,assert()的用法像是一种“契约式编程”,在我的理解 ...

  7. CASS 2008的野外操作码

    表D-1  线面状地物符号代码表 坎类(曲):   K(U) + 数(0-陡坎,1-加固陡坎,2-斜坡,3-加固斜坡,4-垄,5-陡崖,6-干沟) 线类(曲):   X(Q) + 数(0-实线,1-内 ...

  8. logresolve - 解析Apache日志中的IP地址为主机名

    logresolve是一个解析Apache访问日志中IP地址的后处理程序. 为了使对名称服务器的影响降到最低,logresolve拥有极为自主的内部散列表缓存, 使每个IP值仅仅在第一次从日志文件中读 ...

  9. bzoj 3611: [Heoi2014]大工程

    #include<iostream> #include<cstdio> #include<cstring> #include<algorithm> #d ...

  10. 【65测试20161114】【字符串】【DP】

    第一题 复制&粘贴: 文件的内容是一个字符串S,对其进行N次复制&粘贴的操作,第i次操作复制位置Ai和位置Bi之间的所有文字,然后在位置Ci粘贴.这里位置x表示字符串的第x个字符的后面 ...