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 ...
随机推荐
- 基于MPLAB X IDE配置位设置讲解
http://blog.csdn.net/superanters/article/details/8541171 在讲基于MPLAB X IDE 配置位配置前我先讲讲如何配置配置位. 比如PICLF1 ...
- 使用fastJSON解析HashMap中的数据
import java.util.HashMap; import java.util.Iterator; import java.util.Map; import java.util.Map.Entr ...
- hdu6188&&百度之星初赛(B) T5
度度熊的交易计划 Problem Description 度度熊参与了喵哈哈村的商业大会,但是这次商业大会遇到了一个难题: 喵哈哈村以及周围的村庄可以看做是一共由n个片区,m条公路组成的地区. 由于生 ...
- NGINX: 优化 use 参数
转自:http://blog.sina.com.cn/s/blog_5eaf88f10100gkrq.html Nginx use参数分析对比 下图对比了poll select epoll和kqueu ...
- DataTable转换为实体集合
using System; using System.Collections; using System.Collections.Generic; using System.Data; using S ...
- 颜色混合opengl--glBlendFunc函数
http://www.cnblogs.com/ylwn817/archive/2012/09/07/2675285.html 颜色混合opengl--glBlendFunc函数 原文:http://b ...
- Strlcpy和strlcat——一致的、安全的字符串拷贝和串接函数【转】
转自:http://blog.csdn.net/kailan818/article/details/6731772 英文原文: http://www.gratisoft.us/todd/papers/ ...
- 非常好!!!Linux源代码阅读——中断【转】
Linux源代码阅读——中断 转自:http://home.ustc.edu.cn/~boj/courses/linux_kernel/2_int.html 目录 为什么要有中断 中断的作用 中断的处 ...
- java基础练习 18
import java.util.Scanner; public class Eightheen { /*判断一个素数能被几个9整除*/ public static void main(String[ ...
- Win32环境下代码注入与API钩子的实现(转)
本文详细的介绍了在Visual Studio(以下简称VS)下实现API钩子的编程方法,阅读本文需要基础:有操作系统的基本知识(进程管理,内存管理),会在VS下编写和调试Win32应用程序和动态链接库 ...