The topics are as follows:
Problem- solving ideas: This question has been tossing me for a long time, and I have not found a very suitable method, mainly because there are repeated numbers that lead to repeated results. Finally, try to use a dictionary to record the sequence that meets the conditions to ensure that it does not repeat, but it is Accepted.
code show as below:
class Solution(object): def findSubsequences(self, nums): """ :type nums: List[int] :rtype: List[List[int]] """ res = [] queue = [] dic = {} for i in range(len(nums)): #pair = Pair([nums[i]], [i]) queue.append(([nums[i]], i)) # print queue dic = {} while len(queue) > 0: nl,inx = queue.pop(0) if len(nl) > 1: s = '' for i in nl: s += str(i) s += ',' s = s[:-1] if s not in dic: dic[s] = 1 #res.append(s) for i in range(inx+1,len(nums)): if nl[-1] <= nums[i]: queue.append((nl + [nums[i]], i)) for i in dic.iterkeys(): rl = i.split(',') rl2 = [] for i in rl: rl2.append(int(i)) res.append(rl2) return (res)