最美情侣中文字幕电影,在线麻豆精品传媒,在线网站高清黄,久久黄色视频

歡迎光臨散文網(wǎng) 會員登陸 & 注冊

leetcode463. Island Perimeter

2022-02-26 10:22 作者:您是打尖兒還是住店呢  | 我要投稿

You are given?row x col?grid?representing a map where?grid[i][j] = 1?represents?land and?grid[i][j] = 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", 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.

?

Example 1:

Input: grid = [[0,1,0,0],[1,1,1,0],[0,1,0,0],[1,1,0,0]]Output: 16Explanation: The perimeter is the 16 yellow stripes in the image above.

Example 2:

Input: grid = [[1]]Output: 4

Example 3:

Input: grid = [[1,0]]Output: 4

如果這個位置上是1,那么加4,當出現(xiàn)相鄰的時候,則需要減去2,所以遍歷左邊跟上邊的所有情況,因為右邊跟下邊會在后面i++,j++的時候遍歷到;

Runtime:?4 ms, faster than?100.00%?of?Java?online submissions for?Island Perimeter.

Memory Usage:?42.9 MB, less than?80.05%?of?Java?online submissions for?Island Perimeter.


leetcode463. Island Perimeter的評論 (共 條)

分享到微博請遵守國家法律
西平县| 巴林左旗| 镇巴县| 博爱县| 永丰县| 晋宁县| 甘德县| 永年县| 皋兰县| 惠州市| 南汇区| 北安市| 虹口区| 化德县| 华宁县| 夏邑县| 清徐县| 万盛区| 普陀区| 曲阜市| 平潭县| 通州市| 浮山县| 资源县| 涿州市| 济宁市| 当阳市| 澎湖县| 绥江县| 临猗县| 宜城市| 莱芜市| 阜阳市| 祥云县| 山阴县| 焦作市| 宿州市| 乳源| 光山县| 调兵山市| 宜黄县|