Python solution by easily checking all combinations


  • 6
      import itertools
    
      def findSubsequences(self, nums):
        ret = []
        for i in range(2, len(nums) + 1):
          ret.extend(set(itertools.combinations(nums, i)))
        return [x for x in ret if self.isIncreasing(x)]
    
      def isIncreasing(self, l):
        for i in range(1, len(l)):
          if l[i - 1] > l[i]:
            return False
        return True

  • 0
    P

    wonder what is the space usage by doing:

    for i in range(2, len(nums) + 1):
      ret += list(set(itertools.combinations(nums, i)))

  • 3

    Just a variation...

    def findSubsequences(self, nums):
        return [x
                for i in range(2, len(nums) + 1)
                for x in set(itertools.combinations(nums, i))
                if all(a <= b for a, b in zip(x, x[1:]))]

  • 0

    @PHOTOFT
    Thanks for your attention.
    I have changed a little my code.


Log in to reply
 

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