[LeetCode] 78. Subsets - c++

mopevxw·2022년 1월 19일
0

LeetCode

목록 보기
8/21

c++풀이

class Solution {
public:
    vector<vector<int>> result;
    
    vector<vector<int>> subsets(vector<int>& nums) {
       vector<int> tmp;
        solve(nums,tmp,0);
        return result;
        
    }
    
    void solve(vector<int>&nums,vector<int>& tmp,int start){
        if(start==nums.size()){
            result.push_back(tmp);
            return;
        }
        tmp.push_back(nums[start]);
        solve(nums,tmp,start+1);
        tmp.pop_back();
        solve(nums,tmp,start+1);
        }
    };

0개의 댓글