MCPcopy
hub / github.com/HuberTRoy/leetCode / remove

Method remove

Design/InsertDeleteGetRandomO(1).py:95–115  ·  view source on GitHub ↗

Removes a value from the set. Returns true if the set contained the specified element. :type val: int :rtype: bool

(self, val)

Source from the content-addressed store, hash-verified

93 return True
94
95 def remove(self, val):
96 """
97 Removes a value from the set. Returns true if the set contained the specified element.
98 :type val: int
99 :rtype: bool
100 """
101
102 if self.data_dict.get(val) is not None:
103 x = self.data_dict.pop(val)
104 y = self.data_list[-1]
105 if y != val:
106
107 self.data_dict[y] = x
108 self.data_list[-1], self.data_list[x] = self.data_list[x], self.data_list[-1]
109
110 self.data_list.pop()
111 self.length -= 1
112
113 return True
114
115 return False
116
117 def getRandom(self):
118 """

Callers 2

ladderLengthMethod · 0.80
selectionSortFunction · 0.80

Calls 2

getMethod · 0.80
popMethod · 0.45

Tested by

no test coverage detected