MCPcopy Create free account
hub / github.com/neetcode-gh/leetcode / remove

Method remove

python/0380-insert-delete-getrandom-o1.py:19–28  ·  view source on GitHub ↗
(self, val: int)

Source from the content-addressed store, hash-verified

17 return True
18
19 def remove(self, val: int) -> bool:
20 if val not in self.dict:
21 return False
22
23 idx, last_element = self.dict[val], self.list[-1]
24 self.list[idx], self.dict[last_element] = last_element, idx
25 self.list.pop()
26 del self.dict[val]
27
28 return True
29
30 def getRandom(self) -> int:
31 return choice(self.list)

Callers

nothing calls this directly

Calls 1

popMethod · 0.45

Tested by

no test coverage detected