463. Island Perimeter
来源:互联网 发布:orange pi淘宝 编辑:程序博客网 时间:2024/06/14 14:54
You are given a map in form of a two-dimensional integer grid where 1 represents land and 0 represents water. 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). The island doesn't have "lakes" (water inside that 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.
Example:
[[0,1,0,0], [1,1,1,0], [0,1,0,0], [1,1,0,0]]Answer: 16Explanation: The perimeter is the 16 yellow stripes in the image below:
Subscribe to see which companies asked this question.
public class Solution { public int islandPerimeter(int[][] grid) { int re = 0;int row = grid.length;int column = grid[0].length;for (int i = 0; i < row; ++i) {for (int j = 0; j < column; ++j) {if (grid[i][j] == 1) {if (j == 0 || grid[i][j - 1] == 0)re++;if (j == column - 1 || grid[i][j + 1] == 0)re++;if (i == 0 || grid[i - 1][j] == 0)re++;if (i == row - 1 || grid[i + 1][j] == 0)re++;}}}return re; }}
0 0
- 463. Island Perimeter
- 463. Island Perimeter
- leetcode 463. Island Perimeter
- leetcode 463. Island Perimeter
- 463. Island Perimeter
- 463. Island Perimeter
- LeetCode 463. Island Perimeter
- 463. Island Perimeter
- Tutorial: 463. Island Perimeter
- 463. Island Perimeter
- 【LeetCode】 463. Island Perimeter
- [leetcode]463. Island Perimeter
- Leetcode-463. Island Perimeter
- 463. Island Perimeter
- Leetcode 463. Island Perimeter
- 463. Island Perimeter
- 463. Island Perimeter*
- 【Leetcode】463. Island Perimeter
- MySQL5.7新特性:lossless replication 无损复制
- Git 读书笔记
- python中的异常捕获处理机制(try...except...等语句)
- 《Ansible自动化运维》—1.(ansible与devops)
- 3. Longest Substring Without Repeating Characters
- 463. Island Perimeter
- C语言中将数组内的元素进行运算
- 【数据结构】——-树和二叉树(二)
- CABasicAnimation的使用
- Stockbroker Grapevine
- WEB开发入门基础
- 如何使用汇编语言实现冒泡排序?
- atexit()函数调用注册的顺序
- 复数类计算(多种运算符重载)