dengxinyi 6 years ago
parent
commit
88d4ec73fa
1 changed files with 26 additions and 0 deletions
  1. 26 0
      hard/668.kth-smallest-number-in-multiplication-table.go

+ 26 - 0
hard/668.kth-smallest-number-in-multiplication-table.go

@@ -0,0 +1,26 @@
+type minHeap [][2]int
+
+func (h minHeap) Len() int { return len(h) }
+func (h minHeap) Less(i, j int) bool {
+	if h[i][0] != h[j][0] {
+		return h[i][0] < h[j][0]
+	}
+	return h[i][1] < h[j][1]
+}
+func (h minHeap) Swap(i, j int) { h[i], h[j] = h[j], h[i] }
+
+func (h *minHeap) Push(x interface{}) {
+	*h = append(*h, x.([2]int))
+}
+
+func (h *minHeap) Pop() interface{} {
+	l := h.Len()
+	x := (*h)[l-1]
+	*h = (*h)[:l-1]
+	return x
+}
+
+func findKthNumber(m int, n int, k int) int {
+	idx := make([]int, m)
+	return 0
+}