463. Island Perimeter Easy

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



1/**
2 * [463] Island Perimeter
3 *
4 * You are given row x col grid representing a map where grid[i][j] = 1 represents land and grid[i][j] = 0 represents water.
5 * Grid cells are connected horizontally/vertically (not diagonally). The grid is completely surrounded by water, and there is exactly one island (i.e., one or more connected land cells).
6 * The island doesn't have "lakes", meaning the water inside isn't connected to the water around the island. One cell is a square with side length 1. The grid is rectangular, width and height don't exceed 100. Determine the perimeter of the island.
7 *  
8 * Example 1:
9 * <img src="https://assets.leetcode.com/uploads/2018/10/12/island.png" style="width: 221px; height: 213px;" />
10 * Input: grid = [[0,1,0,0],[1,1,1,0],[0,1,0,0],[1,1,0,0]]
11 * Output: 16
12 * Explanation: The perimeter is the 16 yellow stripes in the image above.
13 * 
14 * Example 2:
15 * 
16 * Input: grid = [[1]]
17 * Output: 4
18 * 
19 * Example 3:
20 * 
21 * Input: grid = [[1,0]]
22 * Output: 4
23 * 
24 *  
25 * Constraints:
26 * 
27 * 	row == grid.length
28 * 	col == grid[i].length
29 * 	1 <= row, col <= 100
30 * 	grid[i][j] is 0 or 1.
31 * 	There is exactly one island in grid.
32 * 
33 */
34pub struct Solution {}
35
36// problem: https://leetcode.com/problems/island-perimeter/
37// discuss: https://leetcode.com/problems/island-perimeter/discuss/?currentPage=1&orderBy=most_votes&query=
38
39// submission codes start here
40
41impl Solution {
42    pub fn island_perimeter(grid: Vec<Vec<i32>>) -> i32 {
43        0
44    }
45}
46
47// submission codes end
48
49#[cfg(test)]
50mod tests {
51    use super::*;
52
53    #[test]
54    fn test_463() {
55    }
56}
57


Back
© 2025 bowen.ge All Rights Reserved.