Valid Palindrome
来源:互联网 发布:php 爬虫代码 编辑:程序博客网 时间:2024/06/04 00:52
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 i = 0; int j = s.length() - 1; if(j < 1) return true; while(i <= j){ if(!isalnum (s[i])) i++; else if(!isalnum (s[j])) j--; else{ int tmp = abs(s[i] - s[j]); if(tmp == 0 || tmp == 32){ i++; j--; } else return false; } } 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
- 常识判断-国情社情与时政
- java 的排序算法
- 浅谈Java中的hashcode方法
- Java静态内部类
- Linux下的Oracle编程技术
- Valid Palindrome
- 计算最大链路块
- mybatis3学习笔记之Mapper编程
- 小猫统计——导入通达信日K线数据
- 【卡特兰数】hdu 2067 小兔的棋盘
- 最小的k个数
- cache和内存的映射方式
- sublime text2 插件安装方法
- 1. Java简介