File tree Expand file tree Collapse file tree 2 files changed +33
-3
lines changed Expand file tree Collapse file tree 2 files changed +33
-3
lines changed Original file line number Diff line number Diff line change @@ -1323,9 +1323,7 @@ func maxProfit(prices []int) int {
1323
1323
1324
1324
[ 原题链接] ( https://leetcode-cn.com/problems/two-sum-ii-input-array-is-sorted/comments/ )
1325
1325
1326
- ### 思路
1327
-
1328
- 双指针
1326
+ ### 解一:双指针
1329
1327
1330
1328
- 指针 i 指向最左端,从左到右依次循环
1331
1329
- 指针 j 指向最右端,从右到左依次循环
Original file line number Diff line number Diff line change @@ -924,6 +924,38 @@ class Solution(object):
924
924
return True
925
925
```
926
926
927
+ 复盘:
928
+
929
+ ``` python
930
+ class Solution :
931
+ def isPalindrome (self , s : str ) -> bool :
932
+ length = len (s)
933
+ i = 0
934
+ j = length - 1
935
+
936
+ while i < j:
937
+ if self .isValid(s[i]) and self .isValid(s[j]):
938
+ if s[i].lower() != s[j].lower():
939
+ return False
940
+ i += 1
941
+ j -= 1
942
+
943
+ if not self .isValid(s[i]):
944
+ i += 1
945
+
946
+ if not self .isValid(s[j]):
947
+ j -= 1
948
+ return True
949
+
950
+ def isValid (self , c ):
951
+ if c.isdigit() or c.isalpha():
952
+ return True
953
+ return False
954
+ ```
955
+
956
+ - 时间复杂度:` O(n) `
957
+ - 空间复杂度:` O(1) `
958
+
927
959
928
960
## 139. 单词拆分
929
961
You can’t perform that action at this time.
0 commit comments