Simple Python AC solution


  • 0
    D
    class Solution(object):
        def findSubsequences(self, nums):
            if not nums:
                return []
            res = set()
            self.helper(nums,0,[],res)
            return [list(elem) for elem in res]
            
            
        def helper(self,nums,start,tmp,res):
            
            if len(tmp)>=2:
                res.add(tuple(tmp))
                
            for i in range(start,len(nums)):
                if not tmp or (i>0 and tmp[-1]<=nums[i]):
                    self.helper(nums,i+1,tmp+[nums[i]],res)
    

    Since lists are unhashable in python, I couldn't get the set of lists( which can be done in Java ). So I made all the sequences as tuples and added them to a set. Returned the resulting set of tuples as a set of lists.


Log in to reply
 

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