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

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

LeetCode 2658. Maximum Number of Fish in a Grid

2023-05-02 10:53 作者:您是打尖兒還是住店呢  | 我要投稿

You are given a?0-indexed?2D matrix?grid?of size?m x n, where?(r, c)?represents:

  • A?land?cell if?grid[r][c] = 0, or

  • A?water?cell containing?grid[r][c]?fish, if?grid[r][c] > 0.

A fisher can start at any?water?cell?(r, c)?and can do the following operations any number of times:

  • Catch all the fish at cell?(r, c), or

  • Move to any adjacent?water?cell.

Return?the?maximum?number of fish the fisher can catch if he chooses his starting cell optimally, or?0?if no water cell exists.

An?adjacent?cell of the cell?(r, c), is one of the cells?(r, c + 1),?(r, c - 1),?(r + 1, c)?or?(r - 1, c)?if it exists.

?

Example 1:

Input: grid = [[0,2,1,0],[4,0,0,3],[1,0,0,4],[0,3,2,0]]

Output: 7

Explanation: The fisher can start at cell (1,3) and collect 3 fish, then move to cell (2,3)?and collect 4 fish.

Example 2:


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

Output: 1

Explanation: The fisher can start at cells (0,0) or (3,3) and collect a single fish.

?

Constraints:

  • m == grid.length

  • n == grid[i].length

  • 1 <= m, n <= 10

  • 0 <= grid[i][j] <= 10

DFS經(jīng)典題目;

我是一直沒(méi)做出來(lái),因?yàn)橛玫撵o態(tài)變量。。。尷尬;


Runtime:?28 ms, faster than?12.44%?of?Java?online submissions for?Maximum Number of Fish in a Grid.

Memory Usage:?43.1 MB, less than?10.36%?of?Java?online submissions for?Maximum Number of Fish in a Grid.


LeetCode 2658. Maximum Number of Fish in a Grid的評(píng)論 (共 條)

分享到微博請(qǐng)遵守國(guó)家法律
广州市| 太仓市| 自贡市| 屯昌县| 宜章县| 土默特左旗| 孟村| 青岛市| 洛阳市| 吉木萨尔县| 凭祥市| 蒙山县| 株洲县| 中牟县| 松阳县| 阿拉善右旗| 新田县| 宁都县| 抚州市| 萝北县| 维西| 汾阳市| 志丹县| 清新县| 尉氏县| 涿州市| 出国| 英德市| 甘泉县| 北票市| 西充县| 明溪县| 麦盖提县| 江口县| 含山县| 黑水县| 浦城县| 乐都县| 无为县| 淄博市| 同心县|