Skip to content

Commit 0fe84d6

Browse files
authored
Update quickstart.md
1 parent 6cd6432 commit 0fe84d6

File tree

1 file changed

+28
-0
lines changed

1 file changed

+28
-0
lines changed

introduction/quickstart.md

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,16 @@ class Solution:
3131
- 循环时,i 不需要到 len-1
3232
- 如果找到目标字符串,len(needle) == j
3333

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+
3444
### [示例 2:subsets](https://leetcode-cn.com/problems/subsets/)
3545

3646
> 给定一组不含重复元素的整数数组 nums,返回该数组所有可能的子集(幂集)。
@@ -78,6 +88,24 @@ class Solution:
7888

7989
说明:后面会深入讲解几个典型的回溯算法问题,如果当前不太了解可以暂时先跳过
8090

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+
81109
## 面试注意点
82110

83111
我们大多数时候,刷算法题可能都是为了准备面试,所以面试的时候需要注意一些点

0 commit comments

Comments
 (0)