Implement the class RepeatList
with the following methods:
add(x)
: add the numberx
to the listcheck()
: returnTrue
if some number repeats on the list, otherwiseFalse
The time complexity of each method should be O(1).
In a file repeatlist.py
, implement a class RepeatList
according to the following template:
class RepeatList: def __init__(self): # TODO def add(self, x): # TODO def check(self): # TODO if __name__ == "__main__": r = RepeatList() print(r.check()) # False r.add(1) r.add(2) r.add(3) print(r.check()) # False r.add(2) print(r.check()) # True r.add(5) print(r.check()) # True