Valid Palindrome
来源:互联网 发布:塔吉克斯坦 知乎 编辑:程序博客网 时间:2024/04/25 23:48
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.
给出一个字符串,检查它是不是一个回文。判断过程中只考虑字母数字的字符并且忽略大小写。
例如:
"A man, a plan, a canal: Panama"是一个回文
"race a car"不是一个回文
注意:
我们定义空字符串为回文
//直接利用俩下标操作!
bool isPalindrome(string s) { // IMPORTANT: Please reset any member data you declared, as // the same Solution instance will be reused for each test case. int left,right; right = s.size()-1; left = 0; while(right > left) { if(!isalnum(s.at(right)))right --;//移动 else if(!isalnum(s.at(left)))left ++;//移动 else if(tolower(s.at(right))== tolower(s.at(left)))//最小化处理! { right --; left ++; } else { return false; } } return true; }
- 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
- Unix书籍
- 2.2-3 & 2.2-4
- which命令
- HDU 1051
- JAVA当中变量什么时候需要初始化?
- Valid Palindrome
- remote_listener 设置问题导致数据库不能打开
- NSDate如何获取一个月后的日期
- 敏捷开发的实战经验
- Android中的Property Animation
- 增强for循环和普通for循环的区别
- VirtualBox安装Win7后提示无法启动,以及0xc0000225错误的解决
- 练习赛11.全排列
- 实现一个简单的服务端推送方案-实例篇Polling(服务端阻塞读)