Skip to content

Commit

Permalink
go implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
Azureki committed May 26, 2019
1 parent d36b99a commit 1ac3b7e
Showing 1 changed file with 23 additions and 0 deletions.
23 changes: 23 additions & 0 deletions 77. Combinations/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package leetcode

func combine(n int, k int) [][]int {
combs := [][]int{}
comb := make([]int, 0, k)
myComb(&combs, &comb, 1, n, k)
return combs

}

func myComb(combs *[][]int, comb *[]int, start, n, k int) {
if k == 0 {
tem := make([]int, len(*comb))
copy(tem, *comb)
*combs = append(*combs, tem)
return
}
for i := start; i <= n; i++ {
*comb = append(*comb, i)
myComb(combs, comb, i+1, n, k-1)
*comb = (*comb)[:len(*comb)-1]
}
}

0 comments on commit 1ac3b7e

Please sign in to comment.