File tree 2 files changed +15
-8
lines changed
Leetcode/0703.Kth-Largest-Element-in-a-Stream
2 files changed +15
-8
lines changed Original file line number Diff line number Diff line change @@ -112,8 +112,11 @@ Acceptance Rate
112
112
[ golang container/heap] ( ../../structures/heap/index.en.md )
113
113
114
114
## Big O
115
- 時間複雜 : ``
116
- 空間複雜 : ``
115
+ 時間複雜 :
116
+ 初始化時間複雜度為: O(nlogk) ,其中 n 為初始化時 nums 的長度;
117
+ 單次插入時間複雜度為: O(logk)
118
+
119
+ 空間複雜 : O(k)。 需要使用優先佇列存儲前 k 大的元素
117
120
118
121
## 來源
119
122
* 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 (
5
5
"sort"
6
6
)
7
7
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)
13
11
14
- // 時間複雜 O(), 空間複雜 O()
12
+ // 空間複雜 : O(k)。 需要使用優先佇列存儲前 k 大的元素
15
13
type KthLargest struct {
16
14
sort.IntSlice
17
15
k int
@@ -45,6 +43,12 @@ func (kl *KthLargest) Pop() interface{} {
45
43
return v
46
44
}
47
45
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
+
48
52
func KthLargestStream (k int , nums []int , elem []int ) []int {
49
53
obj := Constructor (k , nums )
50
54
result := []int {0 }
You can’t perform that action at this time.
0 commit comments