MCPcopy Create free account
hub / github.com/VanjaRo/LeetCode / Remove

Method Remove

tasks/380.go:38–48  ·  view source on GitHub ↗

** Removes a value from the set. Returns true if the set contained the specified element. */

(val int)

Source from the content-addressed store, hash-verified

36
37/** Removes a value from the set. Returns true if the set contained the specified element. */
38func (this *RandomizedSet) Remove(val int) bool {
39 if setIt, ok := this.valsSet[val]; ok {
40 last := this.vals[len(this.vals)-1]
41 this.vals[setIt.ind] = last
42 this.vals = this.vals[:len(this.vals)-1]
43 this.valsSet[last] = valEl{last, setIt.ind}
44 delete(this.valsSet, val)
45 return true
46 }
47 return false
48}
49
50/** Get a random element from the set. */
51func (this *RandomizedSet) GetRandom() int {

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected