Skip to content

Latest commit

 

History

History
24 lines (22 loc) · 647 Bytes

1582.md

File metadata and controls

24 lines (22 loc) · 647 Bytes

1582. Special Positions in a Binary Matrix

Solution 1

class Solution(object):
    def numSpecial(self, mat):
        """
        :type mat: List[List[int]]
        :rtype: int
        """
        ans = 0
        row_sum = [0] * len(mat)
        col_sum = [0] * len(mat[0])
        for i in range(len(mat)):
            for j in range(len(mat[0])):
                row_sum[i] += mat[i][j]
                col_sum[j] += mat[i][j]
        for i in range(len(mat)):
            for j in range(len(mat[0])):
                if mat[i][j] == 1 and row_sum[i] == 1 and col_sum[j] == 1:
                    ans += 1
        return ans