# 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

 */
```
````
