Sunday, July 13, 2014

[Leetcode] Subsets I and II

Problem

1. Given a set of distinct integers, S, return all possible subsets.
2. Given a collection of integers that might contain duplicates, S, return all possible subsets.
1. For example, if S = [1,2,3], a solution is:
[
  [3],
  [1],
  [2],
  [1,2,3],
  [1,3],
  [2,3],
  [1,2],
  []
]

2. For example, if S = [1,2,2], a solution is:
  [2],
  [1],
  [1,2,2],
  [2,2],
  [1,2],
  []
]
Note:
  • Elements in a subset must be in non-descending order.
  • The solution set must not contain duplicate subsets.

Code





No comments:

Post a Comment