-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy path432.全-o-1-的数据结构.go
72 lines (53 loc) · 1.8 KB
/
432.全-o-1-的数据结构.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
/*
* @lc app=leetcode.cn id=432 lang=golang
*
* [432] 全 O(1) 的数据结构
*
* https://leetcode-cn.com/problems/all-oone-data-structure/description/
*
* algorithms
* Hard (35.52%)
* Likes: 18
* Dislikes: 0
* Total Accepted: 959
* Total Submissions: 2.7K
* Testcase Example: '["AllOne","getMaxKey","getMinKey"]\n[[],[],[]]'
*
* 实现一个数据结构支持以下操作:
*
*
* Inc(key) - 插入一个新的值为 1 的 key。或者使一个存在的 key 增加一,保证 key 不为空字符串。
* Dec(key) - 如果这个 key 的值是 1,那么把他从数据结构中移除掉。否者使一个存在的 key 值减一。如果这个 key
* 不存在,这个函数不做任何事情。key 保证不为空字符串。
* GetMaxKey() - 返回 key 中值最大的任意一个。如果没有元素存在,返回一个空字符串""。
* GetMinKey() - 返回 key 中值最小的任意一个。如果没有元素存在,返回一个空字符串""。
*
*
* 挑战:以 O(1) 的时间复杂度实现所有操作。
*
*/
type AllOne struct {
}
/** Initialize your data structure here. */
func Constructor() AllOne {
}
/** Inserts a new key <Key> with value 1. Or increments an existing key by 1. */
func (this *AllOne) Inc(key string) {
}
/** Decrements an existing key by 1. If Key's value is 1, remove it from the data structure. */
func (this *AllOne) Dec(key string) {
}
/** Returns one of the keys with maximal value. */
func (this *AllOne) GetMaxKey() string {
}
/** Returns one of the keys with Minimal value. */
func (this *AllOne) GetMinKey() string {
}
/**
* Your AllOne object will be instantiated and called as such:
* obj := Constructor();
* obj.Inc(key);
* obj.Dec(key);
* param_3 := obj.GetMaxKey();
* param_4 := obj.GetMinKey();
*/