Documentation
¶
Overview ¶
Package insert_delete_getrandom_o1 https://leetcode-cn.com/problems/insert-delete-getrandom-o1/
380. O(1) 时间插入、删除和获取随机元素
设计一个支持在平均 时间复杂度 O(1) 下,执行以下操作的数据结构。
- insert(val):当元素 val 不存在时,向集合中插入该项。
- remove(val):元素 val 存在时,从集合中移除该项。
- getRandom:随机返回现有集合中的一项。每个元素应该有相同的概率被返回。
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type RandomizedSet ¶
type RandomizedSet struct {
// contains filtered or unexported fields
}
func Constructor ¶
func Constructor() RandomizedSet
Constructor Initialize your data structure here.
func (*RandomizedSet) GetRandom ¶
func (this *RandomizedSet) GetRandom() int
GetRandom Get a random element from the set.
func (*RandomizedSet) Insert ¶
func (this *RandomizedSet) Insert(val int) bool
Insert Inserts a value to the set. Returns true if the set did not already contain the specified element.
func (*RandomizedSet) Remove ¶
func (this *RandomizedSet) Remove(val int) bool
Remove Removes a value from the set. Returns true if the set contained the specified element.
Click to show internal directories.
Click to hide internal directories.