Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

子集 #39

Open
JesseZhao1990 opened this issue Jul 21, 2018 · 0 comments
Open

子集 #39

JesseZhao1990 opened this issue Jul 21, 2018 · 0 comments

Comments

@JesseZhao1990
Copy link
Owner

JesseZhao1990 commented Jul 21, 2018

image

/**
 * @param {number[]} nums
 * @return {number[][]}
 */
var subsets = function(nums) {
    var res = [];
    function dfs(nums,arr,j){
        res.push([...arr]);
        for(var i=j;i<nums.length;i++){
            arr.push(nums[i]);
            dfs(nums,arr,i+1);
            arr.pop();
        }
    }
    dfs(nums,[],0);
    return res;
};

// var nums = [1,2,3]
// console.log(subsets(nums))

解题思路:

image

LeetCode原题地址:https://leetcode-cn.com/problems/subsets/description/

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant