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.

Solution:

     bool isAlphanumberic(char a) {
if(a >= && a <= ||
(a >= && a <= ) ||
(a >= && a <= ))
return true;
return false;
}
bool isPalindrome(string s) {
if(s.size() == )
return true;
int start = ;
int end = s.size() - ;
while(start < end) {
if(isAlphanumberic(s[start]) && isAlphanumberic(s[end]) ){
if(s[start] >= )
s[start] -= ;
if(s[end] >= )
s[end] -= ;
if(s[start] != s[end]) {
return false;
}else {
start ++;
end --;
}
}else if(!isAlphanumberic(s[start])){
start ++;
}else if(!isAlphanumberic(s[end])) {
end --;
}
}
return true;
}

Valid Palindrome [LeetCode]的更多相关文章

  1. Valid Palindrome leetcode java

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

  2. Valid Palindrome ---- LeetCode 125

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

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

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

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

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

  5. [Leetcode][JAVA] Valid Palindrome

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

  6. 【LeetCode OJ】Valid Palindrome

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

  7. LeetCode——Valid Palindrome

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

  8. [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 ...

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

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

随机推荐

  1. node-webkit中使用sqlite3(MAC平台)

    前言 最近使用node-webkit开发一款博客发布软件,来替换难用的Windows Live Writer(主要是对Markdown标签的支持很差劲).为了解决博文信息临时保存的问题,想到了使用sq ...

  2. require或include相对路径多层嵌套引发的问题

    require或include相对路径多层嵌套引发的问题   php中require/include 包含相对路径的解决办法 在PHP中require,include一个文件时,大都是用相对路径,是个 ...

  3. Datatypes In SQLite Version 3

    http://www.sqlite.org/datatype3.html http://stackoverflow.com/questions/7337882/what-is-the-differen ...

  4. shell脚本批量ping测试IP是否通

    #!/bin/bash rm -f result.txt cat ip.txt | fping > result.txt 2行代码就搞定,很方便,初学shell,很强大,问了下同事,但是shel ...

  5. FLASH CC 2015 CANVAS (七)总结

    FLASH CC 2015 CANVAS (一至七)确切来说是自己在摸索学习过程中而写.所以定为“开荒教程”. 去年年底转战H5,半年中一直非常忙也不敢用CC来做项目,担心有BUG或者无法实现需求,所 ...

  6. PHP爬虫抓取网页内容 (simple_html_dom.php)

    使用simple_html_dom.php,下载|文档 因为抓取的只是一个网页,所以比较简单,整个网站的下次再研究,可能用Python来做爬虫会好些. <meta http-equiv=&quo ...

  7. effect c++ 口诀。

    常用条款,写成口诀,记住.知其所以,也要时时使用. 1)习惯c++: 联替const初. 2)构造,复制,析构: 要知默,构赋析. 若不需,明拒绝. 构析不调虚. 异不逃析构. 基析要虚函. 赋值操, ...

  8. [转载] 读《UNIX网络编程 卷1:套接字联网API》

    原文: http://cstdlib.com/tech/2014/10/09/read-unix-network-programming-1/ 文章写的很清楚, 适合初学者 最近看了<UNIX网 ...

  9. c#获取url请求的返回值(转)

    有两种方式获取. 方法一: /// <summary> /// 获取url的返回值 /// </summary> /// <param name="url&qu ...

  10. 手机CPU知识扫盲:谈谈手机CPU架构与原理 (全

    CPU是手机上面最复杂,最贵的Soc(芯片),担任的也是手机中大脑的位 置,是手机跑分性能的决定性硬件.智能手机发展到今天,各大手机CPU厂商也从春秋战国逐渐到了现在四国鼎立的时代(高通,MTK,三星 ...