添加 0491.递增子序列 python3版本

添加 0491.递增子序列 python3版本
This commit is contained in:
jojoo15
2021-05-28 00:09:28 +02:00
committed by GitHub
parent fa25fab461
commit 60624686a8

View File

@ -229,7 +229,28 @@ class Solution {
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