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.

bool ischar(char & ch)
{
if('a' <= ch && ch <= 'z') return true;
else if('0' <= ch && ch <= '9') return true;
else if('A' <= ch && ch <= 'Z'){ ch += 32; return true; }
else return false;
} bool isPalindrome(string s) {
// Start typing your C/C++ solution below
// DO NOT write int main() function
int length = s.length();
if(length <= 1)return true; int begin = 0;
int end = length-1;
while(begin < end)
{
while(begin < end && !ischar(s[begin]))
++begin;
while(begin < end && !ischar(s[end]))
--end; if(s[begin++] != s[end--]) return false;
}
return true;
}

leetcode_question_125 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 ...

  3. Leetcode Valid Palindrome

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

  4. [LintCode] Valid Palindrome 验证回文字符串

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

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

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

  6. 25. Valid Palindrome

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

  7. [Leetcode][JAVA] Valid Palindrome

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

  8. Valid Palindrome [LeetCode]

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

  9. 【LeetCode OJ】Valid Palindrome

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

随机推荐

  1. Pros and Cons of T4 in Visual Studio 2008

    Oleg Sych - » Pros and Cons of T4 in Visual Studio 2008 Pros and Cons of T4 in Visual Studio 2008 Po ...

  2. java POI读取excel 2007/2003

    2003版office excel读取 import java.io.FileNotFoundException; import java.io.IOException; import java.io ...

  3. 本人对于JavaScript的一些总结

    类型.值和变量 1.原始类型   数字.字符串和布尔   null空  undefined未定义 2.对象类型 3.类  Array  Function Date RegExp  Error 4.js ...

  4. 【巧妙的模拟】【UVA 10881】 - Piotr's Ants/Piotr的蚂蚁

    </pre></center><center style="font-family: Simsun;font-size:14px;"><s ...

  5. 字符串最小表示法 O(n)算法

    网上看了这篇文章后还是感觉有些地方讲的没有详细的证明所以添加了一点 红色字是博主写的 求字符串的循环最小表示: 上面说的两个字符串同构的,并没有直接先求出Min(s),而是通过指针移动,当某次匹配串长 ...

  6. PHP学习笔记1.1——date()函数的多种用法,取出各种不同格式的时间,非常全面

    语法格式:date(string format.int timestamp); 参数一:format指定输出的日期和时间的格式,具体的参见下表; 参数二:timestamp是可选参数,是时间戳,如果不 ...

  7. U盘变小恢复工具——亲测完美可用

    大白菜U盘,装系统后,U盘损坏,格盘后8G只剩345M,用usbboot恢复到了2G容量.离8G还差很远.用U盘变小恢复工具后,完美恢复到原来大小.在此记录一下,以待下次遇到相似情况使用. 原文地址 ...

  8. React-Native个人信息界面

    最近在做一个小练习项目,用户登陆后需要跳转到用户登录信息界面,加班半个小时终于将界面的布局搞定.接触Rect-Native也有一段时间了,以前没有做过ios,只做过android,就布局和开发效率上来 ...

  9. Repository,UnitOfWork,DbContext(1)

    一.前言 终于到EF了,实在不好意思,最近有点忙,本篇离上一篇发布已经一个多星期了,工作中的小迭代告一段落,终于有点时间来继续我们的架构设计了,在这里先对大家表示歉意. 其实这段时间我并不是把这个系列 ...

  10. jsp基础之 jstl

    JSP标准标签库(JSTL)是一个JSP标签集合,它封装了JSP应用的通用核心功能. JSTL支持通用的.结构化的任务,比如迭代,条件判断,XML文档操作,国际化标签,SQL标签. 除了这些,它还提供 ...