国产精品天干天干,亚洲毛片在线,日韩gay小鲜肉啪啪18禁,女同Gay自慰喷水

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

分享到微博請遵守國家法律
喀喇沁旗| 保山市| 新建县| 运城市| 安丘市| 南平市| 黔南| 唐山市| 昔阳县| 辽宁省| 庆城县| 车险| 资溪县| 武胜县| 崇文区| 阿城市| 高碑店市| 开原市| 社会| 新竹县| 常熟市| 罗田县| 东光县| 集贤县| 兰西县| 兴安盟| 禄丰县| 南汇区| 正安县| 武城县| 太仆寺旗| 措美县| 开江县| 仪陇县| 瑞昌市| 盐城市| 邵阳县| 江永县| 尼玛县| 大姚县| 榆树市|