java.lang.Object
g1501_1600.s1582_special_positions_in_a_binary_matrix.Solution

public class Solution extends Object
1582 - Special Positions in a Binary Matrix.<p>Easy</p> <p>Given an <code>m x n</code> binary matrix <code>mat</code>, return <em>the number of special positions in</em> <code>mat</code><em>.</em></p> <p>A position <code>(i, j)</code> is called <strong>special</strong> if <code>mat[i][j] == 1</code> and all other elements in row <code>i</code> and column <code>j</code> are <code>0</code> (rows and columns are <strong>0-indexed</strong> ).</p> <p><strong>Example 1:</strong></p> <p><img src="https://assets.leetcode.com/uploads/2021/12/23/special1.jpg" alt="" /></p> <p><strong>Input:</strong> mat = [[1,0,0],[0,0,1],[1,0,0]]</p> <p><strong>Output:</strong> 1</p> <p><strong>Explanation:</strong> (1, 2) is a special position because mat[1][2] == 1 and all other elements in row 1 and column 2 are 0.</p> <p><strong>Example 2:</strong></p> <p><img src="https://assets.leetcode.com/uploads/2021/12/24/special-grid.jpg" alt="" /></p> <p><strong>Input:</strong> mat = [[1,0,0],[0,1,0],[0,0,1]]</p> <p><strong>Output:</strong> 3</p> <p><strong>Explanation:</strong> (0, 0), (1, 1) and (2, 2) are special positions.</p> <p><strong>Constraints:</strong></p> <ul> <li><code>m == mat.length</code></li> <li><code>n == mat[i].length</code></li> <li><code>1 <= m, n <= 100</code></li> <li><code>mat[i][j]</code> is either <code>0</code> or <code>1</code>.</li> </ul>
  • Constructor Details

    • Solution

      public Solution()
  • Method Details

    • numSpecial

      public int numSpecial(int[][] mat)