Back to problems

Tennis Scoring II

Object-Oriented Programming · Reddit · Medium

Direct State Tracking The most straightforward way to simulate a tennis game is to keep a small, fixed set of variables that reflect the current situation: how many points each player has earned, and whether the game has already been decided. Because every operation depends only on these few numbers, we can respond in constant time without any extra data structures. We store two integer counters pointsA and pointsB and a winner marker gameWinner (initialized to '#', meaning…

Checking your access…