Increasing Subsequences LeetCode solution in Python

1
# Runtime: 750 ms (Top 10.08%) | Memory: 22.4 MB (Top 30.72%)
2
class Solution:
3
def findSubsequences(self, nums: List[int]) -> List[List[int]]:
4
def backtracking(nums, path):
5
# to ensure that the base array has at least 2 elements
6
if len(path) >= 2:
7
res.add(tuple(path))
8
for i in range(len(nums)):
9
# to ensure that every element to be added is equal or larger than the former
10
if not path or path[-1] <= nums[i]:
11
backtracking(nums[i + 1 :], path + [nums[i]])
12

13
res = set()
14
backtracking(nums, [])
15
return res

0

WPM •0 •0

100%

ACC •0 •0

0s

TIME •0