1203. Print in Order
My accepted Python solution to LeetCode problem 1203, Print in Order, running in 50ms.
- Difficulty: Easy
- Python
- Runtime 50ms
- Memory 18MB
- Updated
Read the problem on LeetCode View on GitHub
The problem statement is LeetCode’s and stays on their site. What follows is my accepted solution.
Python
Accepted on LeetCode — runtime 50ms, memory 18MB, accepted 2025-12-29.
import threading
class Foo:
def __init__(self):
self.first_done = threading.Event()
self.second_done = threading.Event()
def first(self, printFirst: 'Callable[[], None]') -> None:
printFirst()
self.first_done.set()
def second(self, printSecond: 'Callable[[], None]') -> None:
self.first_done.wait()
printSecond()
self.second_done.set()
def third(self, printThird: 'Callable[[], None]') -> None:
self.second_done.wait()
printThird()