Python DFS


  • 1
    Y
    class Solution(object):
        def findSubsequences(self, nums):
            """
            :type nums: List[int]
            :rtype: List[List[int]]
            """
            if not nums: return []
            res = []
            for i,n in enumerate(nums):
                if i<>0 and any(n==x for x in nums[:i]): continue
                self.increaseSequence(nums[i+1:], [n], res)
            return res
    
        def increaseSequence(self,nums,seed,res):
            if not nums: return
            for i,n in enumerate(nums):
                if i<>0 and any(n==x for x in nums[:i]): continue
                if n>=seed[-1]:
                    seed.append(n)
                    res.append(deepcopy(seed))
                    self.increaseSequence(nums[i+1:],seed,res)
                    seed.pop()
    

Log in to reply
 

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