Description
Given an m x n binary matrix mat, return the number of special positions. A position is special if mat[i][j] == 1 and all other elements in row i and column j are 0.
Examples
Input:
mat = [[1,0,0],[0,0,1],[1,0,0]]Output:
1Explanation:
Only (1,2) is special.
Input:
mat = [[1]]Output:
1Explanation:
The single element is 1, and it is the only element in its row and column, so it is a special position.
Input:
mat = [[0,0,1,0],[1,0,0,0],[0,0,0,0],[0,1,0,1]]Output:
2Explanation:
Position (0,2) is special because mat[0][2] = 1 and all other elements in row 0 and column 2 are 0. Position (1,0) is special because mat[1][0] = 1 and all other elements in row 1 and column 0 are 0. Position (3,1) is not special because mat[3][3] = 1 in the same row. Position (3,3) is not special because mat[3][1] = 1 in the same row.
Constraints
- •
m == mat.length - •
n == mat[i].length