hoanhan101 / algo

101+ coding interview problems in Go
https://hoanhan.co/posts/101-challenges
MIT License
3.54k stars 374 forks source link

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

Open PolarisCode opened 2 years ago

PolarisCode commented 2 years ago

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 commented 2 years ago
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
}