题目:

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.

说明:

1)注意两点:a、判断满足条件的字符  b、大写变小写(本题认为不区分大小写)

2)字符串为空则true

实现:

 class Solution {
public:
bool isPalindrome(string s) {
if(s.empty()) return true;
int len=strlen(s.c_str());
int i=;
int j=;
for (;i<len;i++)
{
if (isChar(s[i]))//去其他符合,若有大写则大写变小写
{
s[i] = tolower(s[i]);//库函数
s[j++]=s[i];
}
}
s[j]='\0';
if (s[]=='\0') return true;
int len2=strlen(s.c_str());
i=;
while(i<=len2--i) //判断是否回文
{
if(s[i]!=s[len2--i]) return false;
i++;
}
return true;
}
private:
bool isChar(char t)//判断是否满足条件字符
{
if (('a' <= t&&t<='z')||('A' <= t&&t<='Z')||('' <= t&&t<=''))
{
return true;
}
else
return false;
}
};

leetcode题解: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 验证回文字符串

    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 Valid Palindrome 有效回文(字符串)

    class Solution { public: bool isPalindrome(string s) { if(s=="") return true; ) return tru ...

  5. 【LeetCode】9. Palindrome Number 回文数

    作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 公众号:负雪明烛 本文关键词:回文数,回文,题解,Leetcode, 力扣,Python ...

  6. [Leetcode] valid palindrome 验证回文

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

  7. lintcode :Valid Palindrome 有效回文串

    题目: 有效回文串 给定一个字符串,判断其是否为一个回文串.只包含字母和数字,忽略大小写. 样例 "A man, a plan, a canal: Panama" 是一个回文. & ...

  8. [LeetCode] 214. Shortest Palindrome 最短回文串

    Given a string s, you are allowed to convert it to a palindrome by adding characters in front of it. ...

  9. LeetCode Problem 9:Palindrome Number回文数

    描述:Determine whether an integer is a palindrome. Do this without extra space. Some hints: Could nega ...

  10. LeetCode 125. Valid Palindorme (验证回文字符串)

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

随机推荐

  1. 【CF Round 439 A. The Artful Expedient】

    time limit per test 1 second memory limit per test 256 megabytes input standard input output standar ...

  2. Python之多线程:Threading模块

    1.Threading模块提供的类 Thread,Lock,Rlock,Condition,Semaphore,Event,Timer,local 2.threading模块提供的常用的方法 (1)t ...

  3. 【问题帖】压缩图片大小至指定Kb以下

    像PS,QQ影像等都有该功能,将图片大小压缩至指定kb以下. 我也来山寨一把,到目前为止,控制图片的大小,平时的解决方案通过分辨率和质量来控制的. 假定最后压缩的大小是100kb,那么在保证不大于10 ...

  4. aiohttp的学习

    https://hubertroy.gitbooks.io/aiohttp-chinese-documentation/content/aiohttp%E6%96%87%E6%A1%A3/Client ...

  5. Kubernetes监控工具

    #镜像在谷歌上需要FQ#####################################监控工具#当前最新版本 heapster https://github.com/kubernetes/h ...

  6. 3.安装OpenStack-keystone

    安装keystone(控制器上安装) 使用root用户访问数据库 mysql -uroot -ptoyo123 CREATE DATABASE keystone; GRANT ALL PRIVILEG ...

  7. glxgears刷新只有60FPS解决办法

    问题原因在于屏幕的垂直同步刷新率的限制,解决办法是关闭垂直同步刷新. 编辑~/.drirc <driconf> <device screen=" driver=" ...

  8. springMVC多图片压缩上传的实现

    首先需要在配置文件中添加配置: <!--配置文件的视图解析器,用于文件上传,其中ID是固定的:multipartResolver--> <bean id="multipar ...

  9. hbase异常:java.io.IOException: Unable to determine ZooKeeper ensemble

    项目中用到hbase,有时候可能会报一些异常,比如java.io.IOException: Unable to determine ZooKeeper ensemble 等等,当出现这个问题时,根据个 ...

  10. 第一章:1-22、长度为100字节的应用层数据交给运输层传送,需加上20字节的TCP首部。再交给网络层传送,需加上20字节的IP首部。最后交给数据链路层的以太网传送,加上首部和尾部18字节。试求数据的传输效率。  若应用层数据长度为1000字节,数据的传输效率是多少?

    <计算机网络>谢希仁著第四版课后习题答案答: 数据长度为100字节时 传输效率=100/(100+20+20+18)=63.3% 数据长度为1000字节时, 传输效率=1000/(1000 ...