[Leetcode] 78. Subsets

Source: Internet
Author: User

This is a typical depth-first search problem

Class Solution {private:    void Dfs (vector<int>& tmp,vector<vector<int>>& ans,vector <int>& nums,int depth,int N) {        if (depth==n) {            ans.push_back (TMP);            return;        }        Tmp.push_back (nums[depth]);        DFS (tmp,ans,nums,depth+1,n);        Tmp.pop_back ();        DFS (tmp,ans,nums,depth+1,n);    } Public:    vector<vector<int>> subsets (vector<int>& nums) {        vector<vector<int >> ans;        vector<int> tmp;        int n=nums.size ();        DFS (tmp,ans,nums,0,n);        return ans;    };


#include "stdafx.h" #include "vector" #include "iostream" using namespace std;int _tmain (int argc, _tchar* argv[]) {vector& Lt;int> vct;vector<vector<int>> Cap;cap.push_back (VCT); Cap.push_back (VCT); Cout<<cap.size () <<endl;//at this time the output is 2, even if the empty container, also occupies a position return 0;}


[Leetcode] 78. Subsets

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.