
g0001_0100.s0078_subsets.Solution.cpp Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of leetcode-in-all Show documentation
Show all versions of leetcode-in-all Show documentation
104 LeetCode algorithm problem solutions
// #Medium #Top_100_Liked_Questions #Top_Interview_Questions #Array #Bit_Manipulation #Backtracking
// #Algorithm_II_Day_9_Recursion_Backtracking #Udemy_Backtracking/Recursion
// #Big_O_Time_O(2^n)_Space_O(n*2^n) #2024_05_26_Time_0_ms_(100.00%)_Space_8.1_MB_(99.14%)
#include
class Solution {
public:
std::vector> subsets(const std::vector& nums) {
std::vector> res;
std::vector temp;
solve(nums, temp, res, 0);
return res;
}
private:
void solve(const std::vector& nums, std::vector& temp, std::vector>& res, int start) {
res.push_back(temp);
for (int i = start; i < nums.size(); i++) {
temp.push_back(nums[i]);
solve(nums, temp, res, i + 1);
temp.pop_back();
}
}
};
© 2015 - 2025 Weber Informatics LLC | Privacy Policy