Documentation ¶
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
}
*
@author: CodeWater @since: 2023/12/23 @desc: O(1) 时间插入、删除和获取随机元素
*
func Constructor ¶
func Constructor() RandomizedSet
func (*RandomizedSet) GetRandom ¶
func (this *RandomizedSet) GetRandom() int
func (*RandomizedSet) Insert ¶
func (this *RandomizedSet) Insert(val int) bool
func (*RandomizedSet) Remove ¶
func (this *RandomizedSet) Remove(val int) bool
Remove 删除O(1)实现:把删除的元素交换到最后,然后删除最后一个元素即可。
Click to show internal directories.
Click to hide internal directories.