15算法课程 125. Valid Palindrome
来源:互联网 发布:centos 7 yum 安装svn 编辑:程序博客网 时间:2024/06/06 04:09
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.
solution:
循环遍历字符串,将非字母非数字的字符用''直接替换掉得到纯字母数字字符串,然后忽略大小写lower()或者upper()判断是否为回文
code:
class Solution {public: bool isPalindrome(string s) { int left=0,right=s.size()-1; while(left<right) { while(left<right && isalnum(s[left]) == false) left++; while(left<right && isalnum(s[right]) == false ) right--; if(left>=right) return true; if(toupper(s[left]) != toupper(s[right])) return false; left++,right--; } return true; }};
阅读全文
0 0
- 15算法课程 125. Valid Palindrome
- 15算法课程 9. Palindrome Number
- 15算法课程 234. Palindrome Linked List
- 15算法课程 20. Valid Parentheses
- 15算法课程 242. Valid Anagram
- [LeetCode]125.Valid Palindrome
- LeetCode 125. Valid Palindrome
- [Leetcode] 125. Valid Palindrome
- 【LeetCode】125.Valid Palindrome
- [leetcode] 125.Valid Palindrome
- 125. Valid Palindrome
- [leetcode] 125.Valid Palindrome
- Leetcode 125. Valid Palindrome
- 125. Valid Palindrome
- 125. Valid Palindrome LeetCode
- 125. Valid Palindrome
- 【LeetCode】125. Valid Palindrome
- 125. Valid Palindrome
- Docker:《一 》Mac下载安装Docker
- 第4周【项目5
- window下配置JDK以及多个JDK相互切换
- Faster RCNN 中 RPN 的理解
- 微信小程获取当前时期和时间
- 15算法课程 125. Valid Palindrome
- JDBC操作数据库的步骤
- 第九周-项目3
- IPU到底是个什么鬼?
- Spring源码解析——如何阅读源码
- JS基础——深浅拷贝
- SimpleDateFormat的坑
- STM8S 模拟I2C程序
- RabbitMQ 笔记一