Valid Palindrome
来源:互联网 发布:淘宝阅读官网 编辑:程序博客网 时间:2024/04/23 19:38
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) { // Start typing your C/C++ solution below // DO NOT write int main() function string temp; int n = s.size(); for(int i = 0; i < n; ++i){ char &c = s[i]; if(c >='a' && c <= 'z'){ temp += c; } else if(c >= 'A' && c <= 'Z'){ temp += (c- 'A' + 'a'); } else if(c >= '0' && c <= '9'){ temp += c; } } n = temp.size(); if(!n) return true; string rev = temp; rev.assign(temp.rbegin(), temp.rend()); if(temp == rev) return true; return false; }};
- 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
- 升级到ubuntu 12.10 记录
- 【Linux】Ubuntu下C语言访问MySQL数据库入门
- 推箱子游戏开发(二) 键盘事件监听 角色在屏幕上移动
- Memory Alignment
- table固定表头
- Valid Palindrome
- CSS中的一些属性
- google 地图标记
- 数据库中一对多表关联的联合查询重复问题
- Linux命令之cut
- LINK : fatal error LNK1104: 无法打开文件“uiAccess='false' /DEBUG /PDB: 问题的解决方案
- Spring Security加密策略
- 计算机英语复习题
- linux环境下(SUSE 11)安装ArcSDE 10.0 的注意事项(Oracle 11g)