File tree 1 file changed +28
-0
lines changed
1 file changed +28
-0
lines changed Original file line number Diff line number Diff line change @@ -31,6 +31,16 @@ class Solution:
31
31
- 循环时,i 不需要到 len-1
32
32
- 如果找到目标字符串,len(needle) == j
33
33
34
+ ``` Python
35
+ def strStr (self , haystack : str , needle : str ) -> int :
36
+ len_needle = len (needle)
37
+ len_haystack = len (haystack)
38
+ for i in range (len_haystack- len_needle+ 1 ):
39
+ if haystack[i:i+ len_needle] == needle:
40
+ return i
41
+ return - 1
42
+ ```
43
+
34
44
### [ 示例 2:subsets] ( https://leetcode-cn.com/problems/subsets/ )
35
45
36
46
> 给定一组不含重复元素的整数数组 nums,返回该数组所有可能的子集(幂集)。
@@ -78,6 +88,24 @@ class Solution:
78
88
79
89
说明:后面会深入讲解几个典型的回溯算法问题,如果当前不太了解可以暂时先跳过
80
90
91
+ ``` Python
92
+ class Solution :
93
+ def subsets (self , nums : List[int ]) -> List[List[int ]]:
94
+ if not nums:
95
+ return []
96
+ result = []
97
+ nums.sort()
98
+ def backtrack (lst , start ):
99
+ result.append(lst)
100
+ for i in range (start, len (nums)):
101
+ number = nums[i]
102
+ if number not in lst:
103
+ backtrack(lst + [number], i)
104
+ backtrack([], 0 )
105
+ return result
106
+ ```
107
+
108
+
81
109
## 面试注意点
82
110
83
111
我们大多数时候,刷算法题可能都是为了准备面试,所以面试的时候需要注意一些点
You can’t perform that action at this time.
0 commit comments