Leetcode--Valid Palindrome
来源:互联网 发布:oracle sql导出excel 编辑:程序博客网 时间:2024/04/29 17:10
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) { string str=""; //s=tolower(s); for(int i=0;i<s.size();i++) { if(s[i]>='a'&&s[i]<='z') str+=s[i]; else if(s[i]>='A'&&s[i]<='Z') str+=tolower(s[i]); else if(s[i]>='0'&&s[i]<='9') str+=s[i]; else continue; } if(str.size()<=1) return true; int l=0; int r=str.size()-1; while(l<r) { if(str[l]==str[r]) { l++; r--; } else return false; } return true; }};
0 0
- [Leetcode] Valid Palindrome
- Leetcode: Valid Palindrome
- leetcode 55: Valid Palindrome
- [LeetCode] Valid Palindrome
- 【leetcode】Valid Palindrome
- LeetCode - Valid Palindrome
- [leetcode]Valid Palindrome
- [LeetCode]Valid Palindrome
- [Leetcode]Valid Palindrome
- LeetCode-Valid Palindrome
- [leetcode] Valid Palindrome
- LeetCode 125: Valid Palindrome
- LeetCode - Valid Palindrome
- leetcode之Valid Palindrome
- LeetCode | Valid Palindrome
- [leetcode]Valid Palindrome
- 【leetcode】Valid Palindrome
- LeetCode题解:Valid Palindrome
- Hibernate二级缓存详解
- 简单工厂与策略模式
- node.js 初识
- Highcharts 数据点样式
- 怎样发布Android应用
- Leetcode--Valid Palindrome
- Android数据过滤器:Filter
- Android学习 ContentProvider数据更新与Observer模式
- 《Linux程序设计》——信号量、共享内存和消息队列
- IOS音频2:之采用四种方式播放音频文件(二)AudioToolbox AVFoundation OpenAL AUDIO QUEUE(2014-10-17 16:07)
- 资料——Git常用命令整理
- c++定时器
- iOS简单的Socket通讯
- centos win7 双系统