这个题目只要注意大小写问题即可解决,而且我们只关注的是字母和数值

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.

class Solution {
public:
bool isPalindrome(string s) {
int start = , end = s.size() - ;
while (start < end)
{
if ('a' <= s[start] && s[start] <= 'z' || 'A' <= s[start] && s[start] <= 'Z' ||
'' <= s[start] && s[start] <= '')
{
bool tag = true;
while (tag)
{
if ('a' <= s[end] && s[end] <= 'z' || 'A' <= s[end] && s[end] <= 'Z' ||
'' <= s[end] && s[end] <= '')
{
if (s[start] == s[end]||s[start]==toupper(s[end])||s[start]==tolower(s[end]))
{
++start;
--end;
tag = false; }
else
{
return false;
}
}
else
{
--end;
tag = true;
}
}
}
else
++start;
}
return true;
}
};

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

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

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

  2. leetcode 125. Valid Palindrome ----- java

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

  3. Java [Leetcode 125]Valid Palindrome

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

  4. [leetcode]125. Valid Palindrome判断回文串

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

  5. LeetCode 125 Valid Palindrome(有效回文)(*)

    翻译 给定一个字符串.确定它是否是回文的,仅仅考虑当中的数字和字符并忽略其它. 比如. "A man, a plan, a canal: Panama" 是回文的. "r ...

  6. Leetcode 125 Valid Palindrome 字符串处理

    题意:判断字符串是否是回文字符串 先将所有的字母和数字字符保留,并将大写字母转化成小写字母,然后将字符串倒置,比较前后两个字符串是否相同. 该题最好的解法可以模仿 Leetcode 345 Rever ...

  7. Java for LeetCode 125 Valid Palindrome

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

  8. [LeetCode] 680. Valid Palindrome II 验证回文字符串 II

    Given a non-empty string s, you may delete at most one character. Judge whether you can make it a pa ...

  9. 125. Valid Palindrome【easy】

    125. Valid Palindrome[easy] Given a string, determine if it is a palindrome, considering only alphan ...

随机推荐

  1. C#判断文件及文件夹是否存在并创建(C#判断文件夹存在)

    protected void Button1_Click(object sender, EventArgs e) { if (Directory.Exists(Server.MapPath(" ...

  2. js正则及常用方法函数总结

    正则表达式作为一种匹配处理字符串的利器在很多语言中都得到了广泛实现和应用,web开发本质上是处理字符串(服务端接受请求处理后拼接字符串作为响应,这在早期的CGI编程中最明显,然后客户端解析字符串进行渲 ...

  3. oracle 自定义异常处理

    --第一种方式:使用raise_application_error抛出自定义异常declare i number:=-1;begin if i=-1 then raise_application_er ...

  4. HBase(一): c#访问hbase组件开发

    HDP2.4安装系列介绍了通过ambari创建hbase集群的过程,但工作中一直采用.net的技术路线,如何去访问基于Java搞的Hbase呢? Hbase提供基于Java的本地API访问,同时扩展了 ...

  5. Struts2 Interceptors

    Alias Interceptor : 别名拦截器 <action name="someAction" class="com.examples.SomeAction ...

  6. windows下shopex农行支付接口开发笔记

    1.首先是配置Java和tomcat 农行文档里的是linux下的说明.window下我们要按照以下在setclasspath.bat里设置JAVA_HOME,JRE_HOME(红色字体部分).设置这 ...

  7. RSA加密工具包

    主要参考: http://www.blogjava.net/icewee/archive/2012/05/19/378570.html http://snowolf.iteye.com/ 基于以上代码 ...

  8. nova分析(6)—— nova service启动过程

    Nova project下面具有多个service,api,compute,sceduler等等,他们的启动过程都几乎类似,这一篇博客就详细记录nova-sceduler的启动过程.文章中贴出的源码都 ...

  9. php xdebug xampp eclipse

    Eclipse配置 一:配置workspace 打开Eclipse for PHP Developers,需要设置workspace,这个必须设置到C:\xampp\htdocs目录,否则待会无法进行 ...

  10. lucene 区分大小写 问题以及解决方案

    转自:http://blog.csdn.net/huaishu/article/details/8543236 本文介绍lucene区分大小的原因,和解决方案.关于lucene大小写敏感问题我总结一下 ...