1277. Count Square Submatrices with All Ones Medium

@problem@discussion
#Array#Dynamic Programming#Matrix



1/**
2 * [1277] Count Square Submatrices with All Ones
3 *
4 * Given a m * n matrix of ones and zeros, return how many square submatrices have all ones.
5 *  
6 * Example 1:
7 * 
8 * Input: matrix =
9 * [
10 *   [0,1,1,1],
11 *   [1,1,1,1],
12 *   [0,1,1,1]
13 * ]
14 * Output: 15
15 * Explanation: 
16 * There are 10 squares of side 1.
17 * There are 4 squares of side 2.
18 * There is  1 square of side 3.
19 * Total number of squares = 10 + 4 + 1 = 15.
20 * 
21 * Example 2:
22 * 
23 * Input: matrix = 
24 * [
25 *   [1,0,1],
26 *   [1,1,0],
27 *   [1,1,0]
28 * ]
29 * Output: 7
30 * Explanation: 
31 * There are 6 squares of side 1.  
32 * There is 1 square of side 2. 
33 * Total number of squares = 6 + 1 = 7.
34 * 
35 *  
36 * Constraints:
37 * 
38 * 	1 <= arr.length <= 300
39 * 	1 <= arr[0].length <= 300
40 * 	0 <= arr[i][j] <= 1
41 * 
42 */
43pub struct Solution {}
44
45// problem: https://leetcode.com/problems/count-square-submatrices-with-all-ones/
46// discuss: https://leetcode.com/problems/count-square-submatrices-with-all-ones/discuss/?currentPage=1&orderBy=most_votes&query=
47
48// submission codes start here
49
50impl Solution {
51    pub fn count_squares(matrix: Vec<Vec<i32>>) -> i32 {
52        0
53    }
54}
55
56// submission codes end
57
58#[cfg(test)]
59mod tests {
60    use super::*;
61
62    #[test]
63    fn test_1277() {
64    }
65}
66


Back
© 2025 bowen.ge All Rights Reserved.