Game of Life

The Game of Life is a cellular automaton where a grid of cells interacts with eight neighbors. Each cell is either live or dead, and the next state is determined based on specific rules: a live cell with fewer than two or more than three live neighbors dies; a live cell with two or three live neighbors continues to live; a dead cell with exactly three live neighbors becomes live. Update the board simultaneously for the next state.

Constraints

  • m == board.length
  • n == board[i].length
  • 1 <= m, n <= 25
  • board[i][j] is 0 or 1
Saving… · 3 lines
class Solution:
def gameOfLife(self, board: List[List[int]]) -> None:

Console

Click Run to execute sample tests.