Python DP solution came from LIS


  • 0
    D

    class Solution(object):

    def findSubsequences(self, nums):
        """
        :type nums: List[int]
        :rtype: List[List[int]]
        """
        res = set()
        dp = []
        for i in range(len(nums)):
            local = [(nums[i],)]
            for j in range(len(dp)):
                if nums[j] <= nums[i]:
                    for comb in dp[j]:
                        newcomb = comb + (nums[i],)
                        if len(newcomb) >= 2:
                            res.add(newcomb)
                        local.append(newcomb)
            dp.append(local)
        return list(res)

Log in to reply
 

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