无码av一区二区三区无码,在线观看老湿视频福利,日韩经典三级片,成 人色 网 站 欧美大片在线观看

歡迎光臨散文網(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的評論 (共 條)

分享到微博請遵守國家法律
深水埗区| 东丰县| 奉新县| 兴安县| 武清区| 金川县| 鸡东县| 桂林市| 太和县| 绥棱县| 双鸭山市| 肃北| 延庆县| 油尖旺区| 沁源县| 杭锦旗| 泊头市| 定西市| 临夏县| 陇川县| 宜昌市| 洞头县| 银川市| 会东县| 日照市| 天津市| 枞阳县| 富蕴县| 栾川县| 肃南| 金山区| 渭南市| 阜南县| 天台县| 林周县| 江阴市| 资源县| 平舆县| 叶城县| 邵阳市| 榕江县|