leetcode125---Valid Palindrome(回文字符串)
来源:互联网 发布:ubuntu无法读取源列表 编辑:程序博客网 时间:2024/05/22 14:19
问题描述:
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) { if(s.size() == 0) return true; int low = 0; int high = s.size()-1; while(low < high) { while(low < high && !isAlphanum(s[low])) {//从前往后遍历,既不是字母又不数字,则略过 low++; } while(low < high && !isAlphanum(s[high])) {//从后往前遍历,既不是字母又不数字,则略过 high--; }//tolower()函数实现将大写转换为小写字母 if(tolower(s[low]) != tolower(s[high])) {//如果对称位置的不相等 return false; } low++; high--; } return true; } bool isAlphanum(char c) { return ('a' <= c && c <= 'z') || ('A' <= c && c <= 'Z') || ('0' <= c && c <= '9'); }};
0 0
- leetcode125---Valid Palindrome(回文字符串)
- [LeetCode125]Valid Palindrome
- LeetCode125—Valid Palindrome
- leetcode125. Valid Palindrome
- leetcode125: Valid Palindrome
- leetcode125. Valid Palindrome
- LeetCode125 Valid Palindrome
- LeetCode125. Valid Palindrome
- LeetCode125. Valid Palindrome
- leetcode125-Valid Palindrome
- 【字符串回文】Valid Palindrome
- Valid Palindrome(回文字符串)
- LeetCode125——Valid Palindrome
- Valid Palindrome 判断回文字符串
- leetcode 刷题:Valid Palindrome(回文字符串)
- (LeetCode)Valid Palindrome --- 判断回文字符串
- 125. Valid Palindrome (回文字符串判断)
- LeetCode Valid Palindrome(验证回文字符串)
- JSP MVC模式
- dB、dbm、dbw、W 相互关系
- Python 包工具之间的关系
- 网络最经典命令行
- android 让一个控件按钮居于底部的几种方法
- leetcode125---Valid Palindrome(回文字符串)
- 使用Git命令把本地项目上传到Github托管
- Hive 1.2.1 UI(HWI)配置
- js事件流机制
- Spring中bean的scope详解
- Altova XMLSpy 2013R1中文版
- Qt,pro文件详解
- Hadoop集群节点的动态增加与删除
- updatedb与locate