Sharing my 8ms C++ solution

  • 2
    class Solution {
        vector<vector<int>> subsets(vector<int>& nums) {
            vector<vector<int>> result;
            int n = nums.size();
            int N = (1<<n);
            int i, j, temp;
            result.resize(N, vector<int>(0));
            for(i=0; i<N; i++)
                for(j=0; j<n; j++)
                    temp = (1<<j);
                    if(i & temp)
                sort(result[i].begin(), result[i].end());
            return result;

Log in to reply

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