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. 异步设备IO 《windows核心编程》第10章学习

    异步IO操作与同步操作区别: 在CreateFile里的FILE_FLAG_OVERLAPPED标志 异步操作函数LPOVERLAPPED参数 接收IO请求完成通知 触发设备内核对象 缺点:同一个设备 ...

  2. Dev GridControl导出

    问题一. DevExpress GridView导出到Excel中不能导出自定义日期 问题描述: 我有一个第一列为日期列的GridView.它在运行时会绑定到日期,但他们通过CustomColumnD ...

  3. git fetch 的简单用法:更新远程代码到本地仓库

    方式一 1. 查看远程仓库 1 2 3 4 5 6 $ git remote -v eoecn https://github.com/eoecn/android-app.git (fetch) eoe ...

  4. 购买vps创建账号后无法登录ftp

    购买了vps,并在后台已经开通了ftp账号,但是前台无法登录.错误提示530.解决方法是: 请检查您ftp账号密码是否输入正确,若确认正确,请您ssh登陆服务器,然后执行sh /www/wdlinux ...

  5. CALayer总结(一)

    1.geometryFlipped   设置为yes,则子图层或者子视图本来相对于左上角放置 改为 相对于左下角放置: 2.contents 3.contentGravity: kCAGravityC ...

  6. 线程入门之sleep

    package com.thread; /** * <sleep:使线程休眠一些时间> * <功能详细描述> * * @author 95Yang */ public clas ...

  7. 阿里云大数据三次技术突围:Greenplum、Hadoop和“飞天”

    阿里云大数据三次技术突围:Greenplum.Hadoop和"飞天"    对于企业来说,到底什么是云计算?相信很多企业都有这样的困惑,让我们一起回到这个原始的起点探讨究竟什么是云 ...

  8. (转)Thread.setDaemon设置说明

    本想搜下python多线程里的setDaemon,发现了这篇文章写得很不错:http://blog.csdn.net/m13666368773/article/details/7245570 Thre ...

  9. Http报头Accept与Content-Type的区别

    Http报头Accept与Content-Type的区别 1.Accept属于请求头, Content-Type属于实体头. Http报头分为通用报头,请求报头,响应报头和实体报头. 请求方的http ...

  10. 转:为什么C++中空类和空结构体大小为1?

    参考:http://www.spongeliu.com/260.html 为什么C++中空类和空结构体大小为1? On November 17, 2010, in C语言, 语言学习, by spon ...