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

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

LeetCode 2679. Sum in a Matrix

2023-05-21 15:52 作者:您是打尖兒還是住店呢  | 我要投稿

You are given a?0-indexed?2D integer array?nums. Initially, your score is?0. Perform the following operations until the matrix becomes empty:

  1. From each row in the matrix, select the largest number and remove it. In the case of a tie, it does not matter which number is chosen.

  2. Identify the highest number amongst all those removed in step 1. Add that number to your?score.

Return?the final?score.

?

Example 1:

Input: nums = [[7,2,1],[6,4,2],[6,5,3],[3,2,1]]

Output: 15

Explanation: In the first operation, we remove 7, 6, 6, and 3. We then add 7 to our score. Next, we remove 2, 4, 5, and 2. We add 5 to our score. Lastly, we remove 1, 2, 3, and 1. We add 3 to our score. Thus, our final score is 7 + 5 + 3 = 15.

Example 2:

Input: nums = [[1]]Output: 1

Explanation: We remove 1 and add it to the answer. We return 1.

?

給你一個(gè)下標(biāo)從 0 開始的二維整數(shù)數(shù)組 nums 。一開始你的分?jǐn)?shù)為 0 。你需要執(zhí)行以下操作直到矩陣變?yōu)榭眨?/p>


矩陣中每一行選取最大的一個(gè)數(shù),并刪除它。如果一行中有多個(gè)最大的數(shù),選擇任意一個(gè)并刪除。

在步驟 1 刪除的所有數(shù)字中找到最大的一個(gè)數(shù)字,將它添加到你的 分?jǐn)?shù) 中。

請(qǐng)你返回最后的 分?jǐn)?shù) 。

可以先將每一行數(shù)組進(jìn)行排序,然后依次求出每一列的最大值,sum求和記錄即可;


Runtime:?16 ms, faster than?88.62%?of?Java?online submissions for?Sum in a Matrix.

Memory Usage:?57 MB, less than?99.68%?of?Java?online submissions for?Sum in a Matrix.


LeetCode 2679. Sum in a Matrix的評(píng)論 (共 條)

分享到微博請(qǐng)遵守國(guó)家法律
彭阳县| 乐山市| 沁源县| 上思县| 清新县| 乐山市| 房山区| 新竹县| 德保县| 肇州县| 哈巴河县| 长武县| 汤阴县| 藁城市| 神木县| 南雄市| 本溪市| 康定县| 凤城市| 旺苍县| 正镶白旗| 遂宁市| 绥阳县| 多伦县| 阳山县| 西充县| 涞源县| 临武县| 白沙| 林州市| 龙海市| 成都市| 南投县| 延寿县| 团风县| 毕节市| 鄯善县| 保靖县| 会东县| 兴义市| 沂南县|