Skip to content

Commit 2a2b35b

Browse files
committed
[LeetCode Sync] Runtime - 0 ms (100.00%), Memory - 18 MB (40.18%)
1 parent 08d2e93 commit 2a2b35b

File tree

2 files changed

+43
-0
lines changed

2 files changed

+43
-0
lines changed

Solutions/0078-subsets/README.md

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
<p>Given an integer array <code>nums</code> of <strong>unique</strong> elements, return <em>all possible</em> <span data-keyword="subset"><em>subsets</em></span> <em>(the power set)</em>.</p>
2+
3+
<p>The solution set <strong>must not</strong> contain duplicate subsets. Return the solution in <strong>any order</strong>.</p>
4+
5+
<p>&nbsp;</p>
6+
<p><strong class="example">Example 1:</strong></p>
7+
8+
<pre>
9+
<strong>Input:</strong> nums = [1,2,3]
10+
<strong>Output:</strong> [[],[1],[2],[1,2],[3],[1,3],[2,3],[1,2,3]]
11+
</pre>
12+
13+
<p><strong class="example">Example 2:</strong></p>
14+
15+
<pre>
16+
<strong>Input:</strong> nums = [0]
17+
<strong>Output:</strong> [[],[0]]
18+
</pre>
19+
20+
<p>&nbsp;</p>
21+
<p><strong>Constraints:</strong></p>
22+
23+
<ul>
24+
<li><code>1 &lt;= nums.length &lt;= 10</code></li>
25+
<li><code>-10 &lt;= nums[i] &lt;= 10</code></li>
26+
<li>All the numbers of&nbsp;<code>nums</code> are <strong>unique</strong>.</li>
27+
</ul>

Solutions/0078-subsets/solution.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
class Solution:
2+
def subsets(self, nums: List[int]) -> List[List[int]]:
3+
def dfs(i: int):
4+
if i == len(nums):
5+
result.append(temp[:])
6+
return
7+
dfs(i + 1)
8+
temp.append(nums[i])
9+
dfs(i + 1)
10+
temp.pop()
11+
12+
result = []
13+
temp = []
14+
dfs(0)
15+
16+
return result

0 commit comments

Comments
 (0)