1582. Special Positions in a Binary Matrix Easy
1/**
2 * [1582] Special Positions in a Binary Matrix
3 *
4 * Given an m x n binary matrix mat, return the number of special positions in mat.
5 * A position (i, j) is called special if mat[i][j] == 1 and all other elements in row i and column j are 0 (rows and columns are 0-indexed).
6 *
7 * Example 1:
8 * <img alt="" src="https://assets.leetcode.com/uploads/2021/12/23/special1.jpg" style="width: 244px; height: 245px;" />
9 * Input: mat = [[1,0,0],[0,0,1],[1,0,0]]
10 * Output: 1
11 * Explanation: (1, 2) is a special position because mat[1][2] == 1 and all other elements in row 1 and column 2 are 0.
12 *
13 * Example 2:
14 * <img alt="" src="https://assets.leetcode.com/uploads/2021/12/24/special-grid.jpg" style="width: 244px; height: 245px;" />
15 * Input: mat = [[1,0,0],[0,1,0],[0,0,1]]
16 * Output: 3
17 * Explanation: (0, 0), (1, 1) and (2, 2) are special positions.
18 *
19 *
20 * Constraints:
21 *
22 * m == mat.length
23 * n == mat[i].length
24 * 1 <= m, n <= 100
25 * mat[i][j] is either 0 or 1.
26 *
27 */
28pub struct Solution {}
29
30// problem: https://leetcode.com/problems/special-positions-in-a-binary-matrix/
31// discuss: https://leetcode.com/problems/special-positions-in-a-binary-matrix/discuss/?currentPage=1&orderBy=most_votes&query=
32
33// submission codes start here
34
35impl Solution {
36 pub fn num_special(mat: Vec<Vec<i32>>) -> i32 {
37 0
38 }
39}
40
41// submission codes end
42
43#[cfg(test)]
44mod tests {
45 use super::*;
46
47 #[test]
48 fn test_1582() {
49 }
50}
51
Back
© 2025 bowen.ge All Rights Reserved.