HTMLify
LeetCode - Print FooBar Alternately - Python
Views: 378 | Author: abh
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 | from time import sleep class FooBar: def __init__(self, n): self.n = n self.next = "foo" def foo(self, printFoo: 'Callable[[], None]') -> None: for i in range(self.n): while self.next != "foo": sleep(0.001) # printFoo() outputs "foo". Do not change or remove this line. printFoo() self.next = "bar" def bar(self, printBar: 'Callable[[], None]') -> None: for i in range(self.n): while self.next != "bar": sleep(0.001) # printBar() outputs "bar". Do not change or remove this line. printBar() self.next = "foo" |