My 8sec ,C++ code using iterator..


  • 0
    J

    class Solution {
    public:
    vector<vector<int> > subsets(vector<int> &S) {

    vector<vector<int> > result,tempRe;
    vector<int> tempVec;
    result.push_back(tempVec);
    
    sort(S.begin(),S.end());
    
    for(vector<int>::iterator it = S.begin();it != S.end();it++)
    {
    	tempRe = result;
    	for(vector<vector<int> >::iterator itvec = tempRe.begin();itvec!= tempRe.end();itvec++)
    	{
    		itvec->push_back(*it);
    	}
    	result.insert(result.begin(),tempRe.begin(),tempRe.end());
    }
    
    return result;
        
    }
    

    };


Log in to reply
 

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