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

歡迎光臨散文網(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ó)家法律
宁南县| 金坛市| 柳林县| 六盘水市| 来安县| 盐津县| 石首市| 阿图什市| 杂多县| 三明市| 宜良县| 彭阳县| 宿州市| 铁力市| 武山县| 淮北市| 松潘县| 寻乌县| 若羌县| 尖扎县| 阳山县| 阿城市| 临夏市| 鹿邑县| 景洪市| 普洱| 云霄县| 琼结县| 韶关市| 富阳市| 堆龙德庆县| 花垣县| 平定县| 泽库县| 南召县| 富宁县| 乐业县| 巩义市| 汽车| 辛集市| 葫芦岛市|