mirror of
https://github.com/krahets/hello-algo.git
synced 2026-09-03 21:57:14 +00:00
feat(go): support new features with go code (#565)
* feat(go): support hash map chaining * feat(go): support hash map open address * feat(go): support simple hash * feat(go): support top k heap * feat(go): support subset sum I * feat(go): support subset sum native * feat(go): support subset sum II * fix(go): fix some problem
This commit is contained in:
@@ -7,6 +7,7 @@ package chapter_heap
|
||||
import (
|
||||
"container/heap"
|
||||
"fmt"
|
||||
"strconv"
|
||||
"testing"
|
||||
|
||||
. "github.com/krahets/hello-algo/pkg"
|
||||
@@ -88,3 +89,13 @@ func TestMyHeap(t *testing.T) {
|
||||
isEmpty := maxHeap.isEmpty()
|
||||
fmt.Printf("\n堆是否为空 %t\n", isEmpty)
|
||||
}
|
||||
|
||||
func TestTopKHeap(t *testing.T) {
|
||||
/* 初始化堆 */
|
||||
// 初始化大顶堆
|
||||
nums := []int{1, 7, 6, 3, 2}
|
||||
k := 3
|
||||
res := topKHeap(nums, k)
|
||||
fmt.Printf("最大的 " + strconv.Itoa(k) + " 个元素为")
|
||||
PrintHeap(*res)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user