iterative simple python beats 97%


  • 1
    Y
    class Solution(object):
        def findSubsequences(self, nums):
            """
            :type nums: List[int]
            :rtype: List[List[int]]
            """
            stack = []
            Set = set()
            for i in range(len(nums)):
                stack.append([])
                for j in range(i-1, -1, -1):
                    if nums[j] <= nums[i]:
                        stack[i].append([nums[j], nums[i]])
                        Set.add((nums[j], nums[i]))
                        for sequence in stack[j]:
                            stack[i].append(sequence + [nums[i]])
                            Set.add(tuple(stack[i][-1]))
                    if nums[j] == nums[i]:
                        break
            return list(Set)
    

Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.