insert_delete_getrandom_o1

package
v0.0.0-...-a70e5fa Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 27, 2022 License: MIT Imports: 2 Imported by: 0

Documentation

Overview

Package insert_delete_getrandom_o1 https://leetcode-cn.com/problems/insert-delete-getrandom-o1/

380. O(1) 时间插入、删除和获取随机元素

设计一个支持在平均 时间复杂度 O(1) 下,执行以下操作的数据结构。

  1. insert(val):当元素 val 不存在时,向集合中插入该项。
  2. remove(val):元素 val 存在时,从集合中移除该项。
  3. 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.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL