My Blog List

[Leetcode Solution] Subsets II

Analysis

  • Two methods applied both of which are pretty straightforward
    • (1) Sort the original array and extract a new array without duplicates but count the number of each element. Then use DFS all possible subset and in each search step, iterate to insert the current element from 0 times to the number of that element times.
    • (2) Sort the original array and extract a new array without duplicates but count the number of each element. Generate the possible subsets iteratively. At each step, copy all of the previous generated results and insert the current element at the end of each results
    • Seems that iterative way should faster then recursive way however the running results are opposite.

Note

Code

DFS

Iteration
UPDATED AT LEETCODE 2ND PASS

No comments:

Post a Comment

Enter you comment