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

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. eclipse打包jar文件(含外部jar包)的方法

    在项目发布前,使用eclipse导出普通的jar包时,如果配置不好,在运行命令Java -jar /test.jar 时可能会出现如下三类错误信息: 1.no main manifest attrib ...

  2. MySQL使用位运算

    通常 我们的数据表中 可能会包含各种状态属性, 例如 blog表中,我们需要有字段表示其是否公开,是否有设置密码,是否被管理员封锁,是否被置顶等等. 也会遇到在后期运维中,策划要求增加新的功能而造成你 ...

  3. php特殊字符过滤,html标签处理

    1,magic_quotes_gpc  默认情况下,PHP 指令 magic_quotes_gpc 为 on,对所有的 GET.POST 和 COOKIE 数据自动运行 addslashes().不要 ...

  4. Env:Cscope安装与配置

    1. 介绍 Cscope是类似于ctags一样的工具,但可认为他是ctags的增强版. 2. 安装 sudo apt-get install cscope 通过源码安装,参照http://blog.c ...

  5. JavaScript-CheckBox全选/反选

    //------------------------------------ // 全/反选 // param checkName checkbox的name属性 //---------------- ...

  6. Chrome插件开发入门(二)——消息传递机制

    Chrome插件开发入门(二)——消息传递机制   由于插件的js运行环境有区别,所以消息传递机制是一个重要内容.阅读了很多博文,大家已经说得很清楚了,直接转一篇@姬小光 的博文,总结的挺好.后面附一 ...

  7. Maven实战

      一.不要重复造轮子     极限编程(XP)是近些年在软件行业红的发紫的敏捷开发方法,强调拥抱变化.   Maven帮助XP团队实现一些核心价值:   1.简单.Maven暴露了一组一致.简洁的操 ...

  8. PLSQL_性能优化工具系列17_Best Practices: Proactive Data Collection for Performance Issues

    占位符 https://support.oracle.com/epmos/faces/DocumentDisplay?_afrLoop=2082062510193540&id=1366133. ...

  9. c++,opencv播放视频

    #include <opencv2\opencv.hpp>#include <iostream> using namespace cv;using namespace std; ...

  10. docker一些命令

    1.创建image(先创建Dockerfile) docker build -t xxx/xxx . 2.删除image docker rmi xxxxx(image id) docker rmi r ...