Number of Bombs in Minesweeper
Last updated
Last updated
Given a list of location of bombs
and a grid of size of r
and c
, return a matrix that reveals the number of bombs that surrounds a cell in the matrix. Denote bombs by -1.
For example:
The Idea: Initialize an empty matrix by r and c. Then places the bombs by their locations. Finally, rotate about each bomb in the matrix and add one to each cell. Overlapping bombs will accumulate upon themselves.
Complexity: O(|bombs|) time and O(1) extra space.