200. Number of Islands Medium
1/**
2 * [200] Number of Islands
3 *
4 * Given an m x n 2D binary grid grid which represents a map of '1's (land) and '0's (water), return the number of islands.
5 * An island is surrounded by water and is formed by connecting adjacent lands horizontally or vertically. You may assume all four edges of the grid are all surrounded by water.
6 *
7 * Example 1:
8 *
9 * Input: grid = [
10 * ["1","1","1","1","0"],
11 * ["1","1","0","1","0"],
12 * ["1","1","0","0","0"],
13 * ["0","0","0","0","0"]
14 * ]
15 * Output: 1
16 *
17 * Example 2:
18 *
19 * Input: grid = [
20 * ["1","1","0","0","0"],
21 * ["1","1","0","0","0"],
22 * ["0","0","1","0","0"],
23 * ["0","0","0","1","1"]
24 * ]
25 * Output: 3
26 *
27 *
28 * Constraints:
29 *
30 * m == grid.length
31 * n == grid[i].length
32 * 1 <= m, n <= 300
33 * grid[i][j] is '0' or '1'.
34 *
35 */
36pub struct Solution {}
37
38// problem: https://leetcode.com/problems/number-of-islands/
39// discuss: https://leetcode.com/problems/number-of-islands/discuss/?currentPage=1&orderBy=most_votes&query=
40
41// submission codes start here
42
43impl Solution {
44 pub fn num_islands(grid: Vec<Vec<char>>) -> i32 {
45 0
46 }
47}
48
49// submission codes end
50
51#[cfg(test)]
52mod tests {
53 use super::*;
54
55 #[test]
56 fn test_200() {
57 }
58}
59
Back
© 2025 bowen.ge All Rights Reserved.