We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
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
给你一个整数数组nums,数组中的元素 互不相同 。返回该数组所有可能的子集(幂集)。
nums
解集 不能 包含重复的子集。你可以按 任意顺序 返回解集。
输入:nums = [1,2,3] 输出:[[],[1],[2],[1,2],[3],[1,3],[2,3],[1,2,3]]
输入:nums = [0] 输出:[[],[0]]
来源:力扣(LeetCode) 链接:https://leetcode-cn.com/problems/subsets 著作权归领扣网络所有。商业转载请联系官方授权,非商业转载请注明出处。
The text was updated successfully, but these errors were encountered:
func subsets(nums []int) [][]int { lengthNum := generate(nums, []int{}, 0, &[][]int{{}}) return lengthNum } func generate(nums []int, set []int, start int, ret *[][]int) [][]int { if start >= len(nums) { return *ret } set = append(set, nums[start]) *ret = append(*ret, set) generate(nums, set, start+1, ret) // 这里要copy一个临时的变量,因为set是一个切片,切片的本事是一个数组的指针,所以会有影响 tmp := make([]int, len(set)-1) copy(tmp, set[:len(set)-1]) generate(nums, tmp, start+1, ret) return *ret }
Sorry, something went wrong.
No branches or pull requests
给你一个整数数组
nums
,数组中的元素 互不相同 。返回该数组所有可能的子集(幂集)。解集 不能 包含重复的子集。你可以按 任意顺序 返回解集。
示例 1:
示例 2:
提示:
来源:力扣(LeetCode)
链接:https://leetcode-cn.com/problems/subsets
著作权归领扣网络所有。商业转载请联系官方授权,非商业转载请注明出处。
The text was updated successfully, but these errors were encountered: