MCPcopy Create free account
hub / github.com/Ainevsia/Leetcode-Rust / subsets

Method subsets

78. Subsets/Solution.cpp:11–22  ·  view source on GitHub ↗

bit mask

Source from the content-addressed store, hash-verified

9public:
10 // bit mask
11 vector<vector<int>> subsets(vector<int>& nums) {
12 int n = nums.size(), p = 1 << n;
13 vector<vector<int>> sub(p);
14 for (int i=0; i<p; i++) {
15 for (int j=0; j<n; j++) {
16 if ((i>>j)&1 == 1) {
17 sub[i].push_back(nums[j]);
18 }
19 }
20 }
21 return sub;
22 }
23};
24
25int main() {

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected