leetcode题解:Valid Palindrome(判断回文)
题目:
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(判断回文)的更多相关文章
- [leetcode]125. Valid Palindrome判断回文串
Given a string, determine if it is a palindrome, considering only alphanumeric characters and ignori ...
- [LeetCode] 125. Valid Palindrome 验证回文字符串
Given a string, determine if it is a palindrome, considering only alphanumeric characters and ignori ...
- [LeetCode] Valid Palindrome 验证回文字符串
Given a string, determine if it is a palindrome, considering only alphanumeric characters and ignori ...
- LeetCode Valid Palindrome 有效回文(字符串)
class Solution { public: bool isPalindrome(string s) { if(s=="") return true; ) return tru ...
- 【LeetCode】9. Palindrome Number 回文数
作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 公众号:负雪明烛 本文关键词:回文数,回文,题解,Leetcode, 力扣,Python ...
- [Leetcode] valid palindrome 验证回文
Given a string, determine if it is a palindrome, considering only alphanumeric characters and ignori ...
- lintcode :Valid Palindrome 有效回文串
题目: 有效回文串 给定一个字符串,判断其是否为一个回文串.只包含字母和数字,忽略大小写. 样例 "A man, a plan, a canal: Panama" 是一个回文. & ...
- [LeetCode] 214. Shortest Palindrome 最短回文串
Given a string s, you are allowed to convert it to a palindrome by adding characters in front of it. ...
- LeetCode Problem 9:Palindrome Number回文数
描述:Determine whether an integer is a palindrome. Do this without extra space. Some hints: Could nega ...
- LeetCode 125. Valid Palindorme (验证回文字符串)
Given a string, determine if it is a palindrome, considering only alphanumeric characters and ignori ...
随机推荐
- 双系统Ubuntu 无 启用wifi选项
安装好双系统进入ubuntu(14.04)后发现只能用有线连接,不能用wifi.网络连接里无启用wifi选项. 1.查询网卡型号,发现是BCM43132 命令: lspci | grep -i n ...
- 《c程序设计语言》读书笔记-5.3-指针实现strcat
#include <stdio.h> #include <math.h> #include <stdlib.h> #include <string.h> ...
- python代理池的实现
https://github.com/wangqifan/ProxyPool http://python.jobbole.com/86994/
- 遍历Collection集合中的6种方法:
下面的代码演示了遍历Collection集合的6种方法,注意Collection集合的遍历远不止于增强for循环,和迭代器两种. 代码如下: package com.qls.traverse; imp ...
- AngularJS中获取ng-repeat动态生成的ng-model值
需求:通过ng-repeat动态生成的CheckBox,实现勾选控制对应的批次号.如图: html: <div class="clearfix"> <div cl ...
- 封装removeClass()
<div class="box haha xixi">123</div> <script> function removeClass(eleme ...
- SublimeText3自动补全python提示
1.SublimeText3下载地址 https://www.sublimetext.com/3 2.安装SublimeText3 3.安装SublimeCodeIntel (1)打开SublimeT ...
- nutch2.3.1源码分析——InjectorJob
InjectorJob实现的功能是:从种子站点文件当中读取站点信息并且将这些站点的个数.url(url以 域名:协议/端口号/路径名 设为形式存储在数据库当中,为了提高读写速度)回写到Context类 ...
- inux下设置mysql数据库字符集utf8
mysql中文乱码解决方法:将mysql数据库编码统一utf8 查看数据库编码: ? 1 <span style="font-size: 16px;"><stro ...
- ios 改变图片大小缩放方法
http://www.cnblogs.com/zhangdadi/archive/2012/11/17/2774919.html http://bbs.csdn.net/topics/39089858 ...