(self, val: int)
| 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) |