diff options
author | crupest <crupest@outlook.com> | 2020-10-09 14:11:24 +0800 |
---|---|---|
committer | crupest <crupest@outlook.com> | 2020-10-09 14:11:24 +0800 |
commit | 5c5a2b2048f230457028a59924858ba80bb9fff8 (patch) | |
tree | 52c7b7186016dfc46f04dbdac7d4c5404651fac5 /works | |
parent | 1e4ccbddefddcf0dfd9966e3b579b994b4efdcbb (diff) | |
download | crupest-5c5a2b2048f230457028a59924858ba80bb9fff8.tar.gz crupest-5c5a2b2048f230457028a59924858ba80bb9fff8.tar.bz2 crupest-5c5a2b2048f230457028a59924858ba80bb9fff8.zip |
import(solutions): Add problem power set lcci .
Diffstat (limited to 'works')
-rw-r--r-- | works/solutions/cpp/power-set-lcci.cpp | 29 |
1 files changed, 29 insertions, 0 deletions
diff --git a/works/solutions/cpp/power-set-lcci.cpp b/works/solutions/cpp/power-set-lcci.cpp new file mode 100644 index 0000000..f502e7c --- /dev/null +++ b/works/solutions/cpp/power-set-lcci.cpp @@ -0,0 +1,29 @@ +#include <vector> + +using std::vector; + +class Solution { +public: + void dfs(const vector<int> &nums, int index, int size, vector<int> ¤t, + vector<vector<int>> &result) { + if (index == size) { + result.push_back(current); + return; + } + + dfs(nums, index + 1, size, current, result); + + current.push_back(nums[index]); + dfs(nums, index + 1, size, current, result); + current.pop_back(); + } + + vector<vector<int>> subsets(vector<int> &nums) { + vector<int> current; + vector<vector<int>> result; + + dfs(nums, 0 , nums.size(), current, result); + + return result; + } +}; |