My 10 lines super clean C++ code


  • 0
    K
        vector<vector<int>> subsets(vector<int>& nums) 
        {
            vector<vector<int>> res;
            for (int i = 0, total = pow(2, nums.size()); i < total; ++i) {
                vector<int> curr;
                for (int j = 0, k = i; k; ++j, k >>= 1) {
                    if (k & 1) curr.push_back(nums[j]);
                } 
                res.push_back(curr);
            }
            return res;
        }
    

Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.