-
Notifications
You must be signed in to change notification settings - Fork 0
/
PracticeP.cpp
50 lines (36 loc) · 1.23 KB
/
PracticeP.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
// .................Generate sub arrays / sets .................
// #include <iostream>
// #include <vector>
// using namespace std;
// void generateSubsets(vector<int>& nums, int index, vector<int>& current, vector<vector<int>>& result) {
// if (index == nums.size()) {
// result.push_back(current);
// return;
// }
// // Exclude the current element
// generateSubsets(nums, index + 1, current, result);
// // Include the current element
// current.push_back(nums[index]);
// generateSubsets(nums, index + 1, current, result);
// // Backtrack to exclude the current element for the next iteration
// current.pop_back();
// }
// vector<vector<int>> subsets(vector<int>& nums) {
// vector<vector<int>> result;
// vector<int> current;
// generateSubsets(nums, 0, current, result);
// return result;
// }
// int main() {
// vector<int> nums = {1, 2, 3};
// vector<vector<int>> result = subsets(nums);
// cout << "All Subsets of the Array:" << endl;
// for (const auto& subset : result) {
// cout << "[ ";
// for (int num : subset) {
// cout << num << " ";
// }
// cout << "]" << endl;
// }
// return 0;
// }