mirror of
https://github.com/autistic-symposium/master-algorithms-py.git
synced 2025-05-02 06:46:18 -04:00
Update random_set.py
This commit is contained in:
parent
a853cb34c5
commit
c2799fec3a
1 changed files with 2 additions and 2 deletions
|
@ -19,8 +19,8 @@ class RandomizedSet:
|
|||
|
||||
def remove(self, val: int) -> bool:
|
||||
if val in self.dict:
|
||||
index = self.dict[val]
|
||||
self.set[index] = self.set[-1]
|
||||
last_element, idx = self.set[-1], self.dict[val]
|
||||
self.set[idx], self.dict[last_element] = last_element, idx
|
||||
self.set.pop()
|
||||
del self.dict[val]
|
||||
return True
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue