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

歡迎光臨散文網(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ó)家法律
保靖县| 西宁市| 昌宁县| 乌鲁木齐县| 金门县| 林甸县| 峨边| 察雅县| 雅江县| 桓台县| 宁海县| 天水市| 山丹县| 云和县| 龙南县| 泌阳县| 罗江县| 惠州市| 彝良县| 长顺县| 思南县| 赤壁市| 洪湖市| 荔浦县| 水城县| 五指山市| 西林县| 桐柏县| 涡阳县| 固阳县| 沧源| 大方县| 汝城县| 青浦区| 澜沧| 连江县| 松原市| 刚察县| 淮阳县| 平定县| 荔波县|