695. Max Area of Island Medium

@problem@discussion
#Array#Depth-First Search#Breadth-First Search#Union Find#Matrix



1/**
2 * [695] Max Area of Island
3 *
4 * You are given an m x n binary matrix grid. An island is a group of 1's (representing land) connected 4-directionally (horizontal or vertical.) You may assume all four edges of the grid are surrounded by water.
5 * The area of an island is the number of cells with a value 1 in the island.
6 * Return the maximum area of an island in grid. If there is no island, return 0.
7 *  
8 * Example 1:
9 * <img alt="" src="https://assets.leetcode.com/uploads/2021/05/01/maxarea1-grid.jpg" style="width: 500px; height: 310px;" />
10 * Input: grid = [[0,0,1,0,0,0,0,1,0,0,0,0,0],[0,0,0,0,0,0,0,1,1,1,0,0,0],[0,1,1,0,1,0,0,0,0,0,0,0,0],[0,1,0,0,1,1,0,0,1,0,1,0,0],[0,1,0,0,1,1,0,0,1,1,1,0,0],[0,0,0,0,0,0,0,0,0,0,1,0,0],[0,0,0,0,0,0,0,1,1,1,0,0,0],[0,0,0,0,0,0,0,1,1,0,0,0,0]]
11 * Output: 6
12 * Explanation: The answer is not 11, because the island must be connected 4-directionally.
13 * 
14 * Example 2:
15 * 
16 * Input: grid = [[0,0,0,0,0,0,0,0]]
17 * Output: 0
18 * 
19 *  
20 * Constraints:
21 * 
22 * 	m == grid.length
23 * 	n == grid[i].length
24 * 	1 <= m, n <= 50
25 * 	grid[i][j] is either 0 or 1.
26 * 
27 */
28pub struct Solution {}
29
30// problem: https://leetcode.com/problems/max-area-of-island/
31// discuss: https://leetcode.com/problems/max-area-of-island/discuss/?currentPage=1&orderBy=most_votes&query=
32
33// submission codes start here
34
35impl Solution {
36    pub fn max_area_of_island(grid: 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_695() {
49    }
50}
51


Back
© 2025 bowen.ge All Rights Reserved.