五月天青色头像情侣网名,国产亚洲av片在线观看18女人,黑人巨茎大战俄罗斯美女,扒下她的小内裤打屁股

歡迎光臨散文網(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ó)家法律
咸丰县| 留坝县| 宁强县| 名山县| 朔州市| 乾安县| 阳山县| 蛟河市| 扎鲁特旗| 拉萨市| 浑源县| 上虞市| 凌海市| 大关县| 柳河县| 闽清县| 新源县| 亳州市| 乌拉特中旗| 兰州市| 志丹县| 柳林县| 罗田县| 修武县| 海阳市| 吉木萨尔县| 潜山县| 策勒县| 永胜县| 宁远县| 沂源县| 富民县| 谷城县| 岱山县| 普安县| 威海市| 林西县| 宽城| 黑水县| 福鼎市| 始兴县|