leetcode-----78. 子集

代码

class Solution {
public:
    vector<vector<int>> subsets(vector<int>& nums) {
        vector<vector<int>> ans;
        int n = nums.size();
        for (int i = 0; i < 1 << n; ++i) {
            vector<int> path;
            for (int j = 0; j < n; ++j) {
                if (i >> j & 1) path.push_back(nums[j]);
            }
            ans.push_back(path);
        }
        return ans;
    }
};
原文地址:https://www.cnblogs.com/clown9804/p/13300898.html