Update README.md

This commit is contained in:
marina 2023-07-31 10:54:00 -07:00 committed by GitHub
parent 50878d0b85
commit a853cb34c5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -32,8 +32,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