bugfree Icon
interview-course
interview-course
interview-course
interview-course
interview-course
interview-course
interview-course
interview-course

Leetcode Problem 348. Design Tic-Tac-Toe

348. Design Tic-Tac-Toe

Leetcode Solutions

Optimized Counting Approach

  1. Initialize arrays rows and cols of size n to zero, and integers diagonal and antiDiagonal to zero.
  2. For each move by player 1, increment the counters rows[row], cols[col], and if the move is on the diagonal, diagonal, or if it's on the anti-diagonal, antiDiagonal.
  3. For each move by player 2, perform the same operation but decrement the counters.
  4. After each move, check if any of the updated counters equal n or -n. If so, the current player wins.
  5. Return the player number if they win, or 0 otherwise.
UML Thumbnail

Brute Force Approach

Ask Question

Programming Language
image/screenshot of info(optional)
Full Screen
Loading...

Suggested Answer

Answer
Full Screen
Copy Answer Code
Loading...