3195. Find the Minimum Area to Cover All Ones I Medium
1/**
2 * [3195] Find the Minimum Area to Cover All Ones I
3 *
4 * You are given a 2D binary array grid. Find a rectangle with horizontal and vertical sides with the smallest area, such that all the 1's in grid lie inside this rectangle.
5 * Return the minimum possible area of the rectangle.
6 *
7 * <strong class="example">Example 1:
8 * <div class="example-block">
9 * Input: <span class="example-io">grid = [[0,1,0],[1,0,1]]</span>
10 * Output: <span class="example-io">6</span>
11 * Explanation:
12 * <img alt="" src="https://assets.leetcode.com/uploads/2024/05/08/examplerect0.png" style="padding: 10px; background: rgb(255, 255, 255); border-radius: 0.5rem; width: 279px; height: 198px;" />
13 * The smallest rectangle has a height of 2 and a width of 3, so it has an area of 2 * 3 = 6.
14 * </div>
15 * <strong class="example">Example 2:
16 * <div class="example-block">
17 * Input: <span class="example-io">grid = [[1,0],[0,0]]</span>
18 * Output: <span class="example-io">1</span>
19 * Explanation:
20 * <img alt="" src="https://assets.leetcode.com/uploads/2024/05/08/examplerect1.png" style="padding: 10px; background: rgb(255, 255, 255); border-radius: 0.5rem; width: 204px; height: 201px;" />
21 * The smallest rectangle has both height and width 1, so its area is 1 * 1 = 1.
22 * </div>
23 *
24 * Constraints:
25 *
26 * 1 <= grid.length, grid[i].length <= 1000
27 * grid[i][j] is either 0 or 1.
28 * The input is generated such that there is at least one 1 in grid.
29 *
30 */
31pub struct Solution {}
32
33// problem: https://leetcode.com/problems/find-the-minimum-area-to-cover-all-ones-i/
34// discuss: https://leetcode.com/problems/find-the-minimum-area-to-cover-all-ones-i/discuss/?currentPage=1&orderBy=most_votes&query=
35
36// submission codes start here
37
38impl Solution {
39 pub fn minimum_area(grid: Vec<Vec<i32>>) -> i32 {
40 0
41 }
42}
43
44// submission codes end
45
46#[cfg(test)]
47mod tests {
48 use super::*;
49
50 #[test]
51 fn test_3195() {
52 }
53}
54
Back
© 2025 bowen.ge All Rights Reserved.