mirror of
https://github.com/youngyangyang04/leetcode-master.git
synced 2025-07-10 04:06:51 +08:00
添加 0491.递增子序列 python3版本
添加 0491.递增子序列 python3版本
This commit is contained in:
@ -229,7 +229,28 @@ class Solution {
|
|||||||
|
|
||||||
|
|
||||||
Python:
|
Python:
|
||||||
|
```python3
|
||||||
|
class Solution:
|
||||||
|
def findSubsequences(self, nums: List[int]) -> List[List[int]]:
|
||||||
|
res = []
|
||||||
|
path = []
|
||||||
|
def backtrack(nums,startIndex):
|
||||||
|
repeat = [] #这里使用数组来进行去重操作
|
||||||
|
if len(path) >=2:
|
||||||
|
res.append(path[:]) #注意这里不要加return,要取树上的节点
|
||||||
|
for i in range(startIndex,len(nums)):
|
||||||
|
if nums[i] in repeat:
|
||||||
|
continue
|
||||||
|
if len(path) >= 1:
|
||||||
|
if nums[i] < path[-1]:
|
||||||
|
continue
|
||||||
|
repeat.append(nums[i]) #记录这个元素在本层用过了,本层后面不能再用了
|
||||||
|
path.append(nums[i])
|
||||||
|
backtrack(nums,i+1)
|
||||||
|
path.pop()
|
||||||
|
backtrack(nums,0)
|
||||||
|
return res
|
||||||
|
```
|
||||||
|
|
||||||
Go:
|
Go:
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user