leetcode_question_125 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.
bool ischar(char & ch)
{
if('a' <= ch && ch <= 'z') return true;
else if('0' <= ch && ch <= '9') return true;
else if('A' <= ch && ch <= 'Z'){ ch += 32; return true; }
else return false;
} bool isPalindrome(string s) {
// Start typing your C/C++ solution below
// DO NOT write int main() function
int length = s.length();
if(length <= 1)return true; int begin = 0;
int end = length-1;
while(begin < end)
{
while(begin < end && !ischar(s[begin]))
++begin;
while(begin < end && !ischar(s[end]))
--end; if(s[begin++] != s[end--]) return false;
}
return true;
}
leetcode_question_125 Valid Palindrome的更多相关文章
- [LeetCode] 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 ...
- Leetcode Valid Palindrome
Given a string, determine if it is a palindrome, considering only alphanumeric characters and ignori ...
- [LintCode] Valid Palindrome 验证回文字符串
Given a string, determine if it is a palindrome, considering only alphanumeric characters and ignori ...
- [LeetCode]题解(python):125 Valid Palindrome
题目来源 https://leetcode.com/problems/valid-palindrome/ Given a string, determine if it is a palindrome ...
- 25. Valid Palindrome
Valid Palindrome Given a string, determine if it is a palindrome, considering only alphanumeric char ...
- [Leetcode][JAVA] Valid Palindrome
Given a string, determine if it is a palindrome, considering only alphanumeric characters and ignori ...
- Valid Palindrome [LeetCode]
Given a string, determine if it is a palindrome, considering only alphanumeric characters and ignori ...
- 【LeetCode OJ】Valid Palindrome
Problem Link: http://oj.leetcode.com/problems/valid-palindrome/ The following two conditions would s ...
随机推荐
- 【转】【漫画解读】HDFS存储原理
根据Maneesh Varshney的漫画改编,以简洁易懂的漫画形式讲解HDFS存储机制与运行原理. 一.角色出演 如上图所示,HDFS存储相关角色与功能如下: Client:客户端,系统使用者,调用 ...
- 【转】android camera(一):camera模组CMM介绍
关键词:android camera CMM 模组 camera参数平台信息:内核:linux系统:android 平台:S5PV310(samsung exynos 4210) 作者:xubin ...
- 也谈---基于 HTTP 长连接的“服务(转载)
这里指讨论基于HTTP的推技术, 诸如flash,applet之类的东西不作分析, 他们就不能说是"纯粹"的浏览器应用了. 首先是一点背景知识, 大家都知道长连接避免了tcp连接的 ...
- 只允许指定IP访问指定端口 ufw
那天工作需要在服务器上指定ip才可以访问指定端口,配置命令如下: (服务器是ubuntu 14.04系统) apt-get install ufw ufw enable ufw default den ...
- Repository,UnitOfWork,DbContext(1)
一.前言 终于到EF了,实在不好意思,最近有点忙,本篇离上一篇发布已经一个多星期了,工作中的小迭代告一段落,终于有点时间来继续我们的架构设计了,在这里先对大家表示歉意. 其实这段时间我并不是把这个系列 ...
- 2014年1月24日 Oracle 事务导读
形象举例: 从 A 账户向 B 账户转账 10000 元 步骤: 1. A - 10000 2. B + 10000 事务的作用就是确保这两步无误执行后提交,若有一个执行不成功则失败. 结束事务的5 ...
- java数据导出成 EXCEL
/** * * @param out 输出流 * @param maplist 数据 * @param title 标题 * @param headers 表头 * @param keys 表头对应的 ...
- mysql数据库 数据类型
char(m) 固定长度字符串,m<=255:处理速度快: varchar(m) 可变长度字符串,m<=255: int(m) 整数型,-214783647到214783648之间,使用u ...
- Nexus远程Maven仓库索引下载教程
下载Maven仓库索引有两种方式: 一.手动下载 首先将索引下载到本地,下载地址:nexus-maven-repository-index.zip 解压索引压缩包,将里面内容全部拷贝 关闭当前Ne ...
- Oracle数据库中如何选择合适的索引类型 .
索引就好象一本字典的目录.凭借字典的目录,我们可以非常迅速的找到我们所需要的条目.数据库也是如此.凭借Oracle数据库的索引,相关语句可以迅速的定位记录的位置,而不必去定位整个表. 虽然说,在表中是 ...