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.

思路:

这题不能更简单了,考察的是徒手写bug的能力= =

代码:

 bool isPalindrome(string s) {
int n = s.length();
int i = ;
int j = n-;
while(i<j){//while(i>j){//蠢哭了
while(!isalnum(s[i]) && i<n) i++;//没加i<n会超时,不看题用isalpha()
while(!isalnum(s[j]) && j>=) j--;
if(i<j && tolower(s[i++]) != tolower(s[j--])) //if(s[i++] != s[j--] && i>j)//自加自减最坑了, 不看题没用tolower()
return false;
}
return true;
}

【题解】【字符串】【Leetcode】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 II 验证回文字符串之二

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

  3. leetcode Valid Palindrome C++&amp;python 题解

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

  4. LeetCode之“字符串”:Valid Palindrome

    题目链接 题目要求: Given a string, determine if it is a palindrome, considering only alphanumeric characters ...

  5. LeetCode——Valid Palindrome

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

  6. LeetCode Valid Palindrome II

    原题链接在这里:https://leetcode.com/problems/valid-palindrome-ii/description/ 题目: Given a non-empty string  ...

  7. LeetCode: Valid Palindrome [125]

    [题目] Given a string, determine if it is a palindrome, considering only alphanumeric characters and i ...

  8. [leetcode]Valid Palindrome @ Python

    原题地址:https://oj.leetcode.com/problems/valid-palindrome/ 题意: Given a string, determine if it is a pal ...

  9. [Leetcode] valid palindrome 验证回文

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

  10. Leetcode Valid Palindrome

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

随机推荐

  1. redhat enterprixe 5.0 DNS 服务配置与管理

    一.了解DNS相关概念 DNS是一个分布式数据库,在本地负责控制整个分布式数据库的部分段,每一段中的数据通过客户机/服务器模式在整个网络上存取.通过采用复制技术和缓存技术使得整个数据库稳定可靠的同时, ...

  2. php和AJAX用户注册演示程序

    <! doctype html public "-//w3c//dtd html 4.0//en" "http://www.w3.org/tr/rec-html14 ...

  3. 使用AlarmManager设置闹钟----之二

    import android.media.MediaPlayer;import android.os.Bundle;import android.app.Activity;import android ...

  4. eclipse ee 装oepe(Oracle Enterprise Pack for Eclipse)插件

    eclipse j2ee 安装weblogic插件Oracle Enterprise Pack for Eclipse(oepe) eclipse j2ee已经集成了常见的几个服务器容器,比如tomc ...

  5. Union all的用法实例sql

    ---Union all的用法实例sqlSELECT TOP (100) PERCENT ID, bid_user_id, UserName, amount, createtime, borrowTy ...

  6. No suitable driver found for jdbc:mysql://localhost/dbname

    把mysql-connector-java的jar包放入jdk/jre/lib/ext文件下

  7. 判断comboBox是否选对了绑定的数据库中的项

    实现: comboBox1下拉列表已绑定数据库,将选中的项保存到数据库时,判断是否已选中下拉列表里的项 如果没选中,或者输入了其他的值,和已绑定的数据不匹配,出现提示框 按钮的点击事件中: strin ...

  8. HDU 1203-Program D

    Description Speakless很早就想出国,现在他已经考完了所有需要的考试,准备了所有要准备的材料,于是,便需要去申请学校了.要申请国外的任何大学,你都要交纳一定的申请费用,这可是很惊人的 ...

  9. 关于equals和hashCode

    equals()和hashCode()是Object类的两个函数,重要性可见一斑,不过我们平时使用却未必能深入理解他们.本文从java doc触发,讲到它们与哈希表的关系,再到具体的实现,就我目前掌握 ...

  10. 解决 “fatal error C1083: ”无法打开包括文件

    添加该项目的附加路径 . 1)右键查看该项目的属性 2)点击配置属性——〉  C/C++  ——〉  常规  ——〉 附加包含目录——〉将缺失文件所在目录添加进去