Valid Palindrome
来源:互联网 发布:怎么禁止软件运行 编辑:程序博客网 时间:2024/05/29 11:33
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) { if(s.size()==0) return true; transform(s.begin(), s.end(), s.begin(), ::tolower); int l=0,r=s.size()-1; while(r>l){ while(r>=0&&((s[r]>'z'||s[r]<'a')&&(s[r]>'9'||s[r]<'0'))) r--; while(l<s.size()&&((s[l]>'z'||s[l]<'a')&&(s[l]>'9'||s[l]<'0'))) l++; if(r<=l) return true; else{ if(s[r]!=s[l]) return false; r--; l++; } } return true; }};
0 0
- Valid Palindrome
- Valid Palindrome
- Valid Palindrome
- Valid Palindrome
- Valid Palindrome
- Valid Palindrome
- valid palindrome
- Valid Palindrome
- Valid Palindrome
- Valid Palindrome
- Valid Palindrome
- Valid Palindrome
- Valid Palindrome
- Valid Palindrome
- Valid Palindrome
- Valid Palindrome
- Valid Palindrome
- Valid Palindrome
- LPWSTR与CString相互转化
- 字符串哈希函数
- java中finally有什么意义呢,在现实中?举例
- 中文分词方法总结
- 自己动手做Web框架—MVC+Front Controller
- Valid Palindrome
- Linux错误号查询
- 理解 Android Build 系统
- 酷炫DIALOG样式
- 位操作(C和指针)
- 每个Mac OS X 命令行用户应当知道的八个终端工具
- mysql 导出导入数据库
- 升级ubuntu14.04之后导致编译linux kernel出错的解决
- java中checked异常和unchecked异常区别?