Implement a class TrackRepeat
with the following methods:
add(x, k)
: add the numberx
to the listk
timescheck()
: returnTrue
if each number on the list has a different number of occurrences, and otherwiseFalse
The time complexity of both methods should be .
For example, the list contains three distinct numbers , and . The number occurs times, the number occurs times, and the number occurs times. Thus each number has a different number of occurrences (, and occurrences).
In a file trackrepeat.py
, implement a class TrackRepeat
according to the following template:
class TrackRepeat: def __init__(self): # TODO def add(self, x, k): # TODO def check(self): # TODO if __name__ == "__main__": t = TrackRepeat() print(t.check()) # True t.add(1, 3) print(t.check()) # True t.add(2, 3) print(t.check()) # False t.add(2, 2) print(t.check()) # True t.add(3, 1) print(t.check()) # True t.add(3, 4) print(t.check()) # False