You are given an n x m integer matrix matrix containing non-negative integers.
A non-zero cell (row, col) checks the cells near it as follows:
x = matrix[row][col].x rows and x columns of (row, col).x.The cell (row, col) is a local maximum if it is non-zero and no considered cell has a value greater than x.
Return an integer denoting the number of local maximums in matrix.
Example 1:
Input: matrix = [[0,0,0,0,0,0,0],[0,0,0,0,0,0,0],[0,0,0,0,0,0,0],[0,0,0,2,0,0,0],[0,0,0,0,0,0,0],[0,0,0,0,0,0,0],[0,0,0,0,0,0,0]]
Output: 1
Explanation:
(3, 3), x = matrix[3][3] = 2.x rows and x columns of (3, 3).x = 2 are ignored.(3, 3) is a local maximum.Example 2:
Input: matrix = [[1,2],[3,4]]
Output: 1
Explanation:
Only the cell with value 4 is a local maximum. Every other non-zero cell considers a cell with a greater value.
Example 3:
Input: matrix = [[1,0,1],[0,1,0],[1,0,1]]
Output: 5
Explanation:
Example 4:
Input: matrix = [[1,1],[1,1]]
Output: 4
Explanation:
All cells have the same value. Therefore, no cell considers another cell with a greater value, so all 4 cells are local maximums.
Constraints:
1 <= n == matrix.length <= 2001 <= m == matrix[i].length <= 2000 <= matrix[i][j] <= 200Loading editor...
[[0,0,0,0,0,0,0],[0,0,0,0,0,0,0],[0,0,0,0,0,0,0],[0,0,0,2,0,0,0],[0,0,0,0,0,0,0],[0,0,0,0,0,0,0],[0,0,0,0,0,0,0]]