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. Android自定义垂直滚动自动选择日期控件

    ------------------本博客如未明正声明转载,皆为原创,转载请注明出处!------------------ 项目中需要一个日期选择控件,该日期选择控件是垂直滚动,停止滚动时需要校正日期 ...

  2. 格而知之8:我所理解的Runtime(3)

    关联对象 14.使用Category对类进行拓展的时候,只能添加方法,而不适合添加属性(可以添加属性,也可以正常使用get方法和set方法,只是不会自动生成以下划线开头命名的成员变量). 可以通过关联 ...

  3. Co-prime Array&&Seating On Bus(两道水题)

     Co-prime Array Time Limit:1000MS     Memory Limit:262144KB     64bit IO Format:%I64d & %I64u Su ...

  4. 初学SSH(其一)

    其实,之前一直搞不清楚,SSH整合后,Spring框架究竟是怎么连接Hibernate,并且怎么结合Dao层的,后来,我在网上查了资料,Spring+hibernate访问数据库有3种方法: 一. 注 ...

  5. 【gcd+数学证明】【HDU1722】 CAKE

    Cake Time Limit: 1000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submi ...

  6. kvm 图形化安装

    为了再后续查看方便,我还是完整的记录kvm图形化安装. 介于网络环境的原因,我选择NAT. 2,安装kvm前的准备工作 2.1 关闭防火墙  setenforce 0    vi /etc/sysco ...

  7. 解决ie6 闪动的问题

    /*解决ie6 闪动的问题*/ html,html body{_background-image:url(about:blank);_background-attachment:fixed}

  8. Spring整合Hibernate 一 - 注入SessionFactory

    Spring3 整合 Hibernate4 - 注入SessionFactory 版本: spring-framework-3.2.4.RELEASE hibernate-release-4.2.5. ...

  9. tomcat配置CATALINA_HOME变量

    1.CATALINA_HOME是TOMCAT安装路径的别名,目的是为了方便使用TOMCAT 2.计算机>属性>环境变量, 新建环境变量.变量名为CATALINA_HOME ,变量值tomc ...

  10. php 函数之 )_each()list()implode()explode()in_array()

    <?php /* implode() 把数组组合成字符串 explode() 把字符串分割成数组 in_array() 检测内容是否在数组中 each()把数组元素拆分成新的数组 list() ...