Valid Palindrome
Given a string, determine if it is a palindrome, considering only alphanumeric characters and ignoring cases.
(回文字符串)
Note: For the purpose of this problem, we define empty string as valid palindrome.
Example:
1. 双指针
两个指针分别指向字符串的首尾,查到符合要求的字符时就判断两者是否相同。具体实现过程如下:
1 | class Solution: |
2.翻转
判断翻转后的字符串与原来是是否一致,空间复杂度是 O(n) 。具体实现过程如下:
1 | class Solution: |