Skip to content

Commit 013835c

Browse files
committed
feat: improve 78
1 parent a50e40f commit 013835c

File tree

1 file changed

+2
-7
lines changed

1 file changed

+2
-7
lines changed

algorithm/78.Subsets/main.go

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,9 @@ package subsets
33
func subsets(nums []int) [][]int {
44
res := [][]int{[]int{}}
55
for _, e := range nums {
6-
currentOutputLength := len(res)
7-
for i := 0; i < currentOutputLength; i++ {
8-
tempSlice := make([]int, len(res[i]))
9-
copy(tempSlice, res[i])
10-
tempSlice = append(tempSlice, e)
11-
res = append(res, tempSlice)
6+
for _, ee := range res {
7+
res = append(res, append([]int{e}, ee...))
128
}
139
}
14-
1510
return res
1611
}

0 commit comments

Comments
 (0)