[LeetCode] Valid Palindrome
2015-07-10 20:40
375 查看
The suggested solution to this problem has given a clear idea. The tricky part of this problem is to handle all the edge cases carefully and write a clean code.
The following code should be self-explanatory. Note that the use of toupper avoid some messy if-else statements.
The following code should be self-explanatory. Note that the use of toupper avoid some messy if-else statements.
class Solution { public: bool isPalindrome(string s) { int l = 0, r = s.length() - 1; while (l < r) { while (l < r && !isalnum(s[l])) l++; if (l >= r) break; while (r > l && !isalnum(s[r])) r--; if (toupper(s[l++]) != toupper(s[r--])) return false; } return true; } };
相关文章推荐
- JAVA多线程和并发执行
- 蚂蚁【A001】
- 奔跑中的2015——运维在路上
- vmware虚拟机下ubuntu设置1080p的有效方法
- 树的实现遍历及应用
- POSIX定时器:timer_settime()的使用
- win7中如何解决“该项不适用于在指定状态下使用”
- Web服务器开发
- java.net.UnknownHostException 异常处理
- openrefactory/c笔记 (一)
- 最大似然估计(MLE)和最大后验概率(MAP)
- 关于ios6 ios7地图使用权限提示框不弹出的原因
- java多线程------
- 集合的位图表示(C语言描述)
- jquery 完成checkbox的全选功能
- Mitmproxy首页、文档和下载 - 支持SSL的HTTP代理 - 开源中国社区
- J2EE设计模式——MVC
- MySQL表损坏:Table XXX is marked as crashed and should be repaired
- Java三大修饰符
- Blog Contents