LeetCode 78. Subsets (Java)

LeetCode 78. Subsets (Java)



Given a set of distinct integers, nums, return all possible subsets (the power set).

Note: The solution set must not contain duplicate subsets.

For example,
If nums = [1,2,3], a solution is:


The problem is a typical depth first search coding problem.

We can have a recursion function to add visited subsets to the final results. Remember to make a deep copy when we need to add subset to the results.

Video Tutorial

Java Solution

Leave a Reply

Your email address will not be published. Required fields are marked *