#1582
Special Positions in a Binary Matrix
newbie · 255 · lc easy +19 · verified · 72.6% accepted · 1,785 likes · top 82%
Description
Given an m x n binary matrix mat, return the count of special positions. A position (i, j) is special when mat[i][j] == 1 and every other element in row i and column j is 0.
Example 1:
Input: mat = [[1,0,0],[0,0,1],[1,0,0]]
Output: 1
Explanation: (1, 2) is a special position because mat[1][2] == 1 and all other elements in row 1 and column 2 are 0.
Example 2:
Input: mat = [[1,0,0],[0,1,0],[0,0,1]]
Output: 3
Explanation: (0, 0), (1, 1) and (2, 2) are special positions.
Code
1
2
3