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

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

LeetCode 1765. Map of Highest Peak

2023-07-01 15:41 作者:您是打尖兒還是住店呢  | 我要投稿

You are given an integer matrix?isWater?of size?m x n?that represents a map of?land?and?water?cells.

  • If?isWater[i][j] == 0, cell?(i, j)?is a?land?cell.

  • If?isWater[i][j] == 1, cell?(i, j)?is a?water?cell.

You must assign each cell a height in a way that follows these rules:

  • The height of each cell must be non-negative.

  • If the cell is a?water?cell, its height must be?0.

  • Any two adjacent cells must have an absolute height difference of?at most?1. A cell is adjacent to another cell if the former is directly north, east, south, or west of the latter (i.e., their sides are touching).

Find an assignment of heights such that the maximum height in the matrix is?maximized.

Return?an integer matrix?height?of size?m x n?where?height[i][j]?is cell?(i, j)'s height. If there are multiple solutions, return?any?of them.


Example 1:

Input: isWater = [[0,1],[0,0]]

Output: [[1,0],[2,1]]

Explanation:?

????????????????????The image shows the assigned heights of each cell. The blue cell is the water cell, and the green cells are the land cells.

Example 2:


Input: isWater = [[0,0,1],[1,0,0],[0,0,0]]

Output: [[1,1,0],[0,1,1],[1,2,2]]

Explanation:?

????????????????????A height of 2 is the maximum possible height of any assignment. Any height assignment that has a maximum height of 2 while still meeting the rules will also be accepted.

-----------------------------------------------------------

給你一個(gè)大小為 m x n 的整數(shù)矩陣 isWater ,它代表了一個(gè)由 陸地 和 水域 單元格組成的地圖。


如果 isWater[i][j] == 0 ,格子 (i, j) 是一個(gè) 陸地 格子。

如果 isWater[i][j] == 1 ,格子 (i, j) 是一個(gè) 水域 格子。

你需要按照如下規(guī)則給每個(gè)單元格安排高度:


每個(gè)格子的高度都必須是非負(fù)的。

如果一個(gè)格子是 水域 ,那么它的高度必須為 0 。

任意相鄰的格子高度差 至多 為 1 。當(dāng)兩個(gè)格子在正東、南、西、北方向上相互緊挨著,就稱它們?yōu)橄噜彽母褡印#ㄒ簿褪钦f(shuō)它們有一條公共邊)

找到一種安排高度的方案,使得矩陣中的最高高度值 最大 。


請(qǐng)你返回一個(gè)大小為 m x n 的整數(shù)矩陣 height ,其中 height[i][j] 是格子 (i, j) 的高度。如果有多種解法,請(qǐng)返回 任意一個(gè) 。


來(lái)源:力扣(LeetCode)

鏈接:https://leetcode.cn/problems/map-of-highest-peak

經(jīng)典的BFS,只是對(duì)于多源的處理,先將所有的水的地址放到Deque中,然后依次遍歷,

遍歷后,將新的元素放到Deque中繼續(xù)遍歷,(只遍歷標(biāo)記是陸地,且位置高度是-1的,也就是之前沒(méi)有遍歷到的)

下面是代碼:

Runtime:?66 ms, faster than?59.02%?of?Java?online submissions for?Map of Highest Peak.

Memory Usage:?166.9 MB, less than?16.39%?of?Java?online submissions for?Map of Highest Peak.


LeetCode 1765. Map of Highest Peak的評(píng)論 (共 條)

分享到微博請(qǐng)遵守國(guó)家法律
河北省| 辰溪县| 湟中县| 道孚县| 临夏市| 芒康县| 綦江县| 赣州市| 六安市| 大港区| 镇原县| 衡阳市| 益阳市| 清远市| 雷州市| 呼玛县| 左贡县| 玉环县| 渭南市| 卫辉市| 大庆市| 晋宁县| 泰顺县| 宣威市| 青河县| 临沭县| 新巴尔虎左旗| 社旗县| 崇仁县| 巩留县| 青田县| 石渠县| 门头沟区| 罗田县| 克什克腾旗| 二连浩特市| 关岭| 仁寿县| 涟源市| 马边| 黑龙江省|