Leetcode: Valid Palindrome
来源:互联网 发布:音乐播放软件知乎 编辑:程序博客网 时间:2024/06/15 12:06
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.
class Solution {public: bool isPalindrome(string s) { int len = s.size(); if(len <= 1) return true; std::transform(s.begin(), s.end(), s.begin(), ::tolower); int front = 0; int back = len-1; while(front < back) { if(!isalnum(s[front])) ++front; else if(!isalnum(s[back])) --back; else { if(s[front] == s[back]) { ++front; --back; } else break; } } if(front >= back) return true; else return false; }};
0 0
- [Leetcode] Valid Palindrome
- Leetcode: Valid Palindrome
- leetcode 55: Valid Palindrome
- [LeetCode] Valid Palindrome
- 【leetcode】Valid Palindrome
- LeetCode - Valid Palindrome
- [leetcode]Valid Palindrome
- [LeetCode]Valid Palindrome
- [Leetcode]Valid Palindrome
- LeetCode-Valid Palindrome
- [leetcode] Valid Palindrome
- LeetCode 125: Valid Palindrome
- LeetCode - Valid Palindrome
- leetcode之Valid Palindrome
- LeetCode | Valid Palindrome
- [leetcode]Valid Palindrome
- 【leetcode】Valid Palindrome
- LeetCode题解:Valid Palindrome
- 几个常见的压缩算法
- Android跑起Cocos2d-x的SimpleGame
- 浅析Struts1和Struts2的Action线程安全问题
- 二叉树的输入输出,遍历结果,和双亲结点的查找
- RTP/RTSP编程
- Leetcode: Valid Palindrome
- P2P之UDP穿透NAT的原理与实现(附源代码)
- myeclipse常用快捷键总结
- 样式和模板快速入门Style,Template
- 为BBB制作专属自己的cape(三)
- load方法的懒加载及原理
- 桑葚干
- HTML手册入口
- 和菜鸟一起学产品之用户体验设计UED