125. 验证回文串
2020-01-14 15:02
148 查看
给定一个字符串,验证它是否是回文串,只考虑字母和数字字符,可以忽略字母的大小写。
说明:本题中,我们将空字符串定义为有效的回文串。
双指针
无论是时间复杂度还是空间复杂度都比用栈好
def isPalindrome(self, s: str) -> bool: l = 0 r = len(s)-1 while l < r: if s[l].isalnum() and s[r].isalnum(): if s[l].upper() == s[r].upper(): l += 1 r -= 1 else: return False else: if not s[l].isalnum(): l += 1 if not s[r].isalnum(): r -= 1 return True
- 点赞
- 收藏
- 分享
- 文章举报
相关文章推荐
- leetcode 125 验证回文串
- 125. 验证回文串
- leetcode-125-验证回文串
- LeetCode125-验证回文串
- leetcode-125-验证回文串
- 125. 验证回文串 Java
- LeetCode 125.验证回文串
- 这个题目让我很迷--验证回文串--Java
- 验证回文串
- 验证回文串
- 验证字符串是否为数字字符串。如‘125’,‘2313.12’等为数字字符串的方法
- Python LeetCode(125.验证回文串)
- 验证回文串(java)
- leetcode-125. Valid Palindrome(验证含有标点符号String是否为回文串)
- LeetCode 125. 验证回文串
- Leetcode题库 - 验证回文串(java语言版)
- Leetcode刷题28-125.验证回文串(C++)
- 验证回文串--leetcode第125题
- Leetcode 125. 验证回文串
- 【leetcode系列】125. 验证回文串