125. Valid Palindrome (Array; Two-Pointers)
2015-10-03 15:41
274 查看
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.
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.
class Solution { public: bool isPalindrome(string s) { if(s.empty()) return true; int sLength = s.length(); int front = -1; int rear = sLength; char cFront; char cRear; while (1) { cFront = s[++front]; cRear = s[--rear]; if(front > rear) break; if(cFront <= 'Z'&& cFront >='A') { cFront +=32; } if(cRear <= 'Z'&& cRear >='A') { cRear +=32; } while( cFront < '0' || (cFront < 'a' && cFront > '9')|| cFront>'z') { cFront = s[++front]; if(front >= rear) break; if(cFront <= 'Z'&& cFront >='A') { cFront +=32; } } while( cRear < '0' || (cRear < 'a' && cRear > '9')|| cRear>'z') { cRear = s[--rear]; if(front >= rear) break; if(cRear <= 'Z'&& cRear >='A') { cRear +=32; } } if(front >= rear) break; if(cFront!=cRear) { return false; } } return true; } };
相关文章推荐
- new class students' list
- 旅行商简化版 DP
- java中调用dll文件的两种方法
- ZOJ-3798-Abs Problem
- Restore IP Addresses
- C/C++中四种不同的类型转换方式
- 洛谷1071 潜伏者
- 输入字符串,输出各个字符的个数(map用法小例)
- eclipse 从Git导入maven项目
- ISO/IEC 9899:2011 条款6.5.6——加法操作符
- 弱校联萌十一大决战之强力热身 E. Rectangle (规律)
- Android回弹效果新思考与更加易用的实现
- 论文相关
- RGB颜色对照表
- UVA - 1588 Kickdown
- LintCode 合并排序数组
- Android自定义View的实现方法,带你一步步深入了解View(四)
- Tengine高性能部署之—安装篇
- 枚举(enum)所占空间
- android stdio简单介绍和使用