Valid Palindrome [LeetCode]
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.
Solution:
bool isAlphanumberic(char a) {
if(a >= && a <= ||
(a >= && a <= ) ||
(a >= && a <= ))
return true;
return false;
}
bool isPalindrome(string s) {
if(s.size() == )
return true;
int start = ;
int end = s.size() - ;
while(start < end) {
if(isAlphanumberic(s[start]) && isAlphanumberic(s[end]) ){
if(s[start] >= )
s[start] -= ;
if(s[end] >= )
s[end] -= ;
if(s[start] != s[end]) {
return false;
}else {
start ++;
end --;
}
}else if(!isAlphanumberic(s[start])){
start ++;
}else if(!isAlphanumberic(s[end])) {
end --;
}
}
return true;
}
Valid Palindrome [LeetCode]的更多相关文章
- Valid Palindrome leetcode java
题目: Given a string, determine if it is a palindrome, considering only alphanumeric characters and ig ...
- Valid Palindrome ---- LeetCode 125
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]题解(python):125 Valid Palindrome
题目来源 https://leetcode.com/problems/valid-palindrome/ Given a string, determine if it is a palindrome ...
- [Leetcode][JAVA] Valid Palindrome
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 ...
- LeetCode——Valid Palindrome
Given a string, determine if it is a palindrome, considering only alphanumeric characters and ignori ...
- [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 ...
- 【一天一道LeetCode】#125. Valid Palindrome
一天一道LeetCode 本系列文章已全部上传至我的github,地址:ZeeCoder's Github 欢迎大家关注我的新浪微博,我的新浪微博 欢迎转载,转载请注明出处 (一)题目 Given a ...
随机推荐
- SpringMVC 配置过滤器解决中文乱码问题
<!-- 字符集过滤器 --> <filter> <filter-name>Charset</filter-name> ...
- ios 学习线路(图片)(摘录)
iOS学习路线
- windows上配置git
windows上配置git1.下载mysisigit进入http://msysgit.github.io/,下载,安装,下一步下一步即可. 2.下载tortoisegit进入http://downlo ...
- More Effective C++ (1)
简单分析总结了more effective c++ 的前十个条款: 剩下的条款to be continue~ 1.仔细区分指针和引用引用必须不能指向空,指针可以指向空,指针初始化是记得赋空值,重载某些 ...
- Redis核心知识之—— 时延问题分析及应对、性能问题和解决方法【★★★★★】
参考网址: Redis时延问题分析及应对:http://www.cnblogs.com/me115/p/5032177.html Redis常见的性能问题和解决方法:http://www.search ...
- Linux基础知识之—— nohup命令使程序在后台运行的方法
在linux操作系统中从后台一直运行某个程序的方法,就是使用nohup命令了. 参照网址:http://www.jb51.net/LINUXjishu/189964.html
- [转载] iptables配置实践
原文: http://wsgzao.github.io/post/iptables/ iptables配置实践 By wsgzao 发表于 2015-07-24 文章目录 1. 前言 2. 更新历史 ...
- GFS Google File System(中文翻译)
Google文件系统 GFS是一个可扩展的分布式文件系统,用于大型的.分布式的.对大量数据进行访问的应用.它运行于廉价的普通硬件上,但可以提供容错功能.它可以给大量的用户提供总体性能较高的服务. 1. ...
- goLang文件遍历
package main import ( "fmt" "io/ioutil" "os" "path/filepath&q ...
- OpenGL的gluPerspective透视投影变换函数详解[转]
函数原型void gluPerspective(GLdouble fovy, GLdouble aspect, GLdouble zNear, GLdouble zFar) 首先得设置gluPersp ...