Number of Bombs in Minesweeper
Given a list of location of bombsand 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:
input: mine_sweeping_reveal([[0,0], [0,1]], 3, 4)
output:
[[-1. -1. 1. 0.]
[ 2. 2. 1. 0.]
[ 0. 0. 0. 0.]]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.
Last updated
Was this helpful?