|
1 | 1 | ## 题目地址(380. 常数时间插入、删除和获取随机元素)
|
2 | 2 |
|
3 |
| -https://leetcode-cn.com/problems/insert-delete-getrandom-o1/ |
| 3 | +https://leetcode-cn.com/problems/insert-delete-getrandom-o1/description/ |
4 | 4 |
|
5 | 5 | ## 题目描述
|
6 | 6 |
|
@@ -38,18 +38,6 @@ randomSet.getRandom();
|
38 | 38 |
|
39 | 39 | ```
|
40 | 40 |
|
41 |
| -## 前置知识 |
42 |
| - |
43 |
| -- 数组 |
44 |
| -- 哈希表 |
45 |
| - |
46 |
| -## 公司 |
47 |
| - |
48 |
| -- 阿里 |
49 |
| -- 腾讯 |
50 |
| -- 百度 |
51 |
| -- 字节 |
52 |
| - |
53 | 41 | ## 思路
|
54 | 42 |
|
55 | 43 | 这是一个设计题。这道题的核心就是考察基本数据结构和算法的操作以及复杂度。
|
@@ -92,15 +80,15 @@ randomSet.getRandom();
|
92 | 80 |
|
93 | 81 | 以依次【1,2,3,4】之后为初始状态,那么此时状态是这样的:
|
94 | 82 |
|
95 |
| - |
| 83 | + |
96 | 84 |
|
97 |
| -而当要插入一个新的5的时候, 我们只需要分别向数组末尾和哈希表中插入这条记录即可。 |
| 85 | +而当要插入一个新的 5 的时候, 我们只需要分别向数组末尾和哈希表中插入这条记录即可。 |
98 | 86 |
|
99 |
| - |
| 87 | + |
100 | 88 |
|
101 | 89 | 而删除的时候稍微有一点复杂:
|
102 | 90 |
|
103 |
| - |
| 91 | + |
104 | 92 |
|
105 | 93 | ## 关键点解析
|
106 | 94 |
|
@@ -170,12 +158,13 @@ class RandomizedSet:
|
170 | 158 | # param_3 = obj.getRandom()
|
171 | 159 | ```
|
172 | 160 |
|
173 |
| -***复杂度分析*** |
| 161 | +**复杂度分析** |
| 162 | + |
174 | 163 | - 时间复杂度:$O(1)$
|
175 | 164 | - 空间复杂度:$O(1)$
|
176 | 165 |
|
177 |
| -更多题解可以访问我的LeetCode题解仓库:https://github.com/azl397985856/leetcode 。 目前已经30K star啦。 |
| 166 | +更多题解可以访问我的 LeetCode 题解仓库:https://github.com/azl397985856/leetcode 。 目前已经 30K star 啦。 |
178 | 167 |
|
179 |
| -大家也可以关注我的公众号《力扣加加》获取更多更新鲜的LeetCode题解 |
| 168 | +大家也可以关注我的公众号《力扣加加》获取更多更新鲜的 LeetCode 题解 |
180 | 169 |
|
181 | 170 | 
|
0 commit comments