LeetCode 125. Valid Palindrome
2016-04-10 10:11
302 查看
Given a string, determine if it is a palindrome, considering only alphanumeric characters and ignoring cases.
For example,
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.
// two pointer problem
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.
// two pointer problem
#include <string> #include <iostream> using namespace std; bool isPalindrome(string s) { if(s.size() <= 1) return true; int i = 0; int j = s.size() - 1; while(i <= j) { if(isalnum(s[i]) && isalnum(s[j])) { if(tolower(s[i]) == tolower(s[j])) { i++; j--; continue; } else { return false; } } if(!isalnum(s[i])) {i++;} if(!isalnum(s[j])) {j--;} } return true; } int main(void) { string tmp = "A man, a plan, a canal : Panama six"; bool res = isPalindrome(tmp); cout << res << endl; }
相关文章推荐
- paoding-rose 之 maven配置
- zend stuido 12.5的插件安装和xdebug调试器的配置和和配置注意
- 并行算法学习之单源最短路径
- Java异常分类及区别
- iptables详解2
- hdu 1505 City Game (hdu1506加强版)
- 数据库锁
- iOS应用程序的生命周期
- 共同学习Java源码--常用数据类型--String(十二)
- maven的学习系列(四)—创建maven项目注意事项
- 动态规划算法——钢条切割问题
- Windows下的Objective-C集成开发环境(IDE)的搭建
- JAVA集合(1)
- 第六周学习进度
- 汉堡评价
- 一个男人关心的东西决定了他的层次
- jetty之maven配置
- 单链表存在环的问题
- iOS面试知识点之内存管理
- KMP字符串匹配,next数组的求解