Description
Apply Game of Life rules to a board in-place. Live cell with 2-3 neighbors survives, dead cell with 3 neighbors becomes live. Return the result as a 2D array.
Examples
Input:
board = [[0,1,0],[0,0,1],[1,1,1],[0,0,0]]Output:
[[0,0,0],[1,0,1],[0,1,1],[0,1,0]]Explanation:
Next state after applying rules.
Input:
board = [[1]]Output:
[[0]]Explanation:
A single live cell with no neighbors dies from underpopulation (fewer than 2 live neighbors), so it becomes 0 in the next state.
Input:
board = [[1,1,0,0],[1,0,1,0],[0,1,0,1],[0,0,1,1]]Output:
[[1,1,0,0],[1,0,1,0],[0,1,0,1],[0,0,1,1]]Explanation:
A 4x4 board demonstrating various Game of Life scenarios: live cells at (0,0) and (0,1) survive with 2-3 neighbors, cell at (1,1) dies from underpopulation (only 1 neighbor), cell at (2,1) dies from isolation, and dead cell at (3,1) becomes alive with exactly 3 neighbors.
Constraints
- •
1 ≤ m, n ≤ 25 - •
board[i][j] is 0 or 1