> For the complete documentation index, see [llms.txt](https://timmybeeflin.gitbook.io/cracking-leetcode/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://timmybeeflin.gitbook.io/cracking-leetcode/weekly-contest/1582.-special-positions-in-a-binary-matrix.md).

# 1582. Special Positions in a Binary Matrix

T: O(mn)

S: O(m+n)

````java
```java
class Solution {
    public int numSpecial(int[][] mat) {
        int m = mat.length;
        int n = mat[0].length;
        int[] rowCount = new int[m];
        int[] colCount = new int[n];
        int count = 0;
        for (int i = 0; i < m; i++) {
            for (int j = 0; j < n; j++) {
                if (mat[i][j] == 1) {
                    rowCount[i]++;
                    colCount[j]++;
                }
            }
        }
        for (int i = 0; i < m; i++) {
            if (rowCount[i] != 1) {
                continue;
            }
            for (int j = 0; j < n; j++) {
                if (mat[i][j] == 1 && colCount[j] == 1) {
                    count++;
                }
            }
        }
        
        return count;
    }
}
/**
[
    [0,0,0,0,0,1,0,0],
    [0,0,0,0,1,0,0,1],
    [0,0,0,0,1,0,0,0],
    [1,0,0,0,1,0,0,0],
    [0,0,1,1,0,0,0,0]
]

ex1: 
1 
1.    x -> only this one
1
  2 0 1

 */
```
````
