leetcode---Valid Palindrome
2016-04-09 21:58
330 查看
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.
For example,
“A man, a plan, a canal: Panama” is a palindrome.
“race a car” is not a palindrome.
class Solution { public: bool isPalindrome(string s) { char ss[100000]; int len = s.length(); int index = 0; for(int i=0; i<len; i++) { if(isalpha(s[i])) ss[index++] = toupper(s[i]); if(isdigit(s[i])) ss[index++] = s[i]; } int l = 0; int r = index - 1; while(l < r) { if(ss[l] != ss[r]) return false; l++; r--; } return true; } };
相关文章推荐
- nginx源码包编译安装
- [Web API] Client 指定請求及回應格式(xml/json)
- 解决Ubuntu下chrome总是在Dock上留两个图标
- android 面试总结(2)
- ubuntu14.04LTS安装steam
- 排序
- Nginx安装手册
- Landoj 1603 - Minimum Sum (暴力&模拟)
- 【剑指 offer】(二十九)—— 数组中出现次数超过一半的数字(及该数字出现的次数)
- 记票统计(华为oj)
- CentOS 7卸载openjdk
- Matlab并行编程方法
- 【Leetcode】:Single Number问题 in java
- 设置内存使用率而启用swap的参数
- Codeblocks快捷键的使用
- jquery图片3D旋绕效果 rotate3Di的操作
- 1001. A+B Format (20)
- 零基础学习JAVA的初期笔记--自己的笔记
- 最大似然估计(like-hood)
- UVa 10340 All in All