How about my solution? ( but not the non-descend order)


  • 0
    Z
    vector<vector<int> > subsets(vector<int> &S)
        	{
        		int len = S.size();
        		int col = 0;
        		vector<int>tem;
        		vector<vector<int>>sub;
        		while (1)
        		{
        
        			for (int i = 0; i != len; ++i)
        			{
        				if ((col&int(pow(2, i))) == int(pow(2, i)))
        				{
        					tem.push_back(S[i]);
        				}
        
        			}
        			
        			
        			sub.push_back(tem);
        			tem.clear();
        			if (col == int(pow(2, len) - 1))
        				break;
        			col++;
        
        
        		}
        		return(sub);
        	}

Log in to reply
 

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