algo icon indicating copy to clipboard operation
algo copied to clipboard

This code will not work properly with this input: [9, 0, 3, 5, 7]

Open PolarisCode opened this issue 2 years ago • 1 comments

This code will not work properly with this input: [9, 0, 3, 5, 7] Subsets_test.go https://github.com/hoanhan101/algo/blob/46d524ff83ff5fc2f4c6d2a63daa1f7b11a883ae/gtci/subsets_test.go#L47

PolarisCode avatar May 01 '22 10:05 PolarisCode

func subsets(nums []int) [][]int {
	var result [][]int
	result = append(result, []int{})

	for j := 0; j < len(nums); j++ {
		l := len(result)
		for i := 0; i < l; i++ {
			var dst []int
			dst = append(dst, result[i]...)
			dst = append(dst, nums[j])
			result = append(result, dst)
		}
	}

	return result
}

PolarisCode avatar May 01 '22 11:05 PolarisCode