We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
2 parents a1a3762 + 9a5b905 commit 6e5de0bCopy full SHA for 6e5de0b
78. Subsets
@@ -0,0 +1,25 @@
1
+class Solution {
2
+public:
3
+ vector<vector<int>> subsets(vector<int>& nums) {
4
+ vector<vector<int>> result;
5
+ vector<int> curr;
6
+
7
+ function<void(int)> explore = [&](int index) {
8
+ if (index == nums.size()) {
9
+ result.push_back(curr);
10
+ return;
11
+ }
12
13
+ // Include the current element
14
+ curr.push_back(nums[index]);
15
+ explore(index + 1);
16
+ curr.pop_back(); // Backtrack
17
18
+ // Exclude the current element
19
20
+ };
21
22
+ explore(0);
23
+ return result;
24
25
+};
0 commit comments