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;
    }
};
posted @ 2020-07-14 18:56  景云ⁿ  阅读(50)  评论(0编辑  收藏  举报