Valid Palindrome
来源:互联网 发布:mac book 用什么vpn 编辑:程序博客网 时间:2024/06/06 17:54
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.
» Solve this problem去掉S中的无关字符,将大写字母转换为小写,之后就是简单的回文串判断。
- class Solution {
- public:
- bool isPalindrome(string s) {
- // Start typing your C/C++ solution below
- // DO NOT write int main() function
- string t = "";
- for (int i = 0; i < s.length(); i++) {
- if (s[i] >= 'a' && s[i] <= 'z' || s[i] >= '0' && s[i] <= '9' || s[i] >= 'A' && s[i] <= 'Z') {
- if (s[i] >= 'A' && s[i] <= 'Z') {
- t += (s[i] - 'A' + 'a');
- }
- else {
- t += s[i];
- }
- }
- }
- if (t == "") {
- return true;
- }
- for (int i = 0; i < t.length() / 2; i++) {
- if (t[i] != t[t.length() - i - 1]) {
- 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
- suse11sp3网卡别名修改经验(dell服务器)(sybaseIQ15.4获取hostid)
- 原码一位乘法与补码一位乘法
- android 内部文件读取
- 【VIM技巧】多行缩进
- android 开发必知的50个诀窍 2.1 include的使用
- Valid Palindrome
- 线程安全的概念,实现线程安全的几种方法
- 完美解决Ubuntu下vi编辑器方向键变字母的问题
- django中使用ajax(post)进行异步请求
- 主键和外键
- Symbols From Another External Module
- Redis应用场景
- python 调用 webservice
- python httplib 模块