File tree Expand file tree Collapse file tree 2 files changed +15
-8
lines changed
Leetcode/0703.Kth-Largest-Element-in-a-Stream Expand file tree Collapse file tree 2 files changed +15
-8
lines changed Original file line number Diff line number Diff line change @@ -112,8 +112,11 @@ Acceptance Rate
112112[ golang container/heap] ( ../../structures/heap/index.en.md )
113113
114114## Big O
115- 時間複雜 : ``
116- 空間複雜 : ``
115+ 時間複雜 :
116+ 初始化時間複雜度為: O(nlogk) ,其中 n 為初始化時 nums 的長度;
117+ 單次插入時間複雜度為: O(logk)
118+
119+ 空間複雜 : O(k)。 需要使用優先佇列存儲前 k 大的元素
117120
118121## 來源
119122* https://leetcode.com/problems/kth-largest-element-in-a-stream/
Original file line number Diff line number Diff line change @@ -5,13 +5,11 @@ import (
55 "sort"
66)
77
8- /**
9- * Your KthLargest object will be instantiated and called as such:
10- * obj := Constructor(k, nums);
11- * param_1 := obj.Add(val);
12- */
8+ // 時間複雜 :
9+ // 初始化時間複雜度為: O(nlogk) ,其中 n 為初始化時 nums 的長度;
10+ // 單次插入時間複雜度為: O(logk)
1311
14- // 時間複雜 O(), 空間複雜 O()
12+ // 空間複雜 : O(k)。 需要使用優先佇列存儲前 k 大的元素
1513type KthLargest struct {
1614 sort.IntSlice
1715 k int
@@ -45,6 +43,12 @@ func (kl *KthLargest) Pop() interface{} {
4543 return v
4644}
4745
46+ /**
47+ * Your KthLargest object will be instantiated and called as such:
48+ * obj := Constructor(k, nums);
49+ * param_1 := obj.Add(val);
50+ */
51+
4852func KthLargestStream (k int , nums []int , elem []int ) []int {
4953 obj := Constructor (k , nums )
5054 result := []int {0 }
You can’t perform that action at this time.
0 commit comments