Valid Palindrome
来源:互联网 发布:ubuntu界面太小 编辑:程序博客网 时间:2024/05/01 04:22
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: char strLwr(char c) { if(c-'A'>=0 && c-'A'<=26) { return 'a'+c-'A'; } return c; } bool isAlphanumeric(char c) { if(c-'0'>=0 && c-'0'<=9) { return true; } if (c-'a'>=0 && c-'a'<=26) { return true; } if (c-'A'>=0 && c-'A' <= 26) { return true; } return false; } bool isPalindrome(string s) { int len = s.length(); string ss = ""; int i; for(i=0; i<len; ++i) { if(isAlphanumeric(s[i])) { ss += strLwr(s[i]); } } string rss(ss.rbegin(), ss.rend()); if (ss == rss) { return true; } return false; }};
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
- android-code-handler
- android虚拟机安装成功
- Supermap iserver client 空间查询关联属性过滤示例
- IOS控制器管理
- (2)JS语法注意事项(变量类型)
- Valid Palindrome
- ZXing二维码
- 韦东山视频第1期 学习计划
- CSS vertical-align的介绍
- 网络流最大流算法参考程序
- C程序修改控制台颜色
- UVa-10487-Closest Sums
- Two Sum[leetcode]
- Linux platform compile execuable makefile