LeetCode491. 递增子序列
- 题目链接
- 代码
题目链接
https://leetcode.cn/problems/non-decreasing-subsequences/
代码
class Solution:
def backtracking(self, nums, index, result, path):
if len(path) > 1:
result.append(path[:])
uset = set()
for i in range(index, len(nums)):
if (path and nums[i] < path[-1]) or nums[i] in uset:
continue
uset.add(nums[i])
path.append(nums[i])
self.backtracking(nums, i + 1, result, path)
path.pop()
def findSubsequences(self, nums: List[int]) -> List[List[int]]:
result = []
self.backtracking(nums, 0, result, [])
return result