Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commite31fbf6

Browse files
committed
Add solution #2500
1 parent551586c commite31fbf6

File tree

2 files changed

+39
-0
lines changed

2 files changed

+39
-0
lines changed

‎README.md‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2264,6 +2264,7 @@
22642264
2496|[Maximum Value of a String in an Array](./solutions/2496-maximum-value-of-a-string-in-an-array.js)|Easy|
22652265
2498|[Frog Jump II](./solutions/2498-frog-jump-ii.js)|Medium|
22662266
2499|[Minimum Total Cost to Make Arrays Unequal](./solutions/2499-minimum-total-cost-to-make-arrays-unequal.js)|Hard|
2267+
2500|[Delete Greatest Value in Each Row](./solutions/2500-delete-greatest-value-in-each-row.js)|Easy|
22672268
2501|[Longest Square Streak in an Array](./solutions/2501-longest-square-streak-in-an-array.js)|Medium|
22682269
2502|[Design Memory Allocator](./solutions/2502-design-memory-allocator.js)|Medium|
22692270
2503|[Maximum Number of Points From Grid Queries](./solutions/2503-maximum-number-of-points-from-grid-queries.js)|Hard|
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
/**
2+
* 2500. Delete Greatest Value in Each Row
3+
* https://leetcode.com/problems/delete-greatest-value-in-each-row/
4+
* Difficulty: Easy
5+
*
6+
* You are given an m x n matrix grid consisting of positive integers.
7+
*
8+
* Perform the following operation until grid becomes empty:
9+
* - Delete the element with the greatest value from each row. If multiple such elements exist,
10+
* delete any of them.
11+
* - Add the maximum of deleted elements to the answer.
12+
*
13+
* Note that the number of columns decreases by one after each operation.
14+
*
15+
* Return the answer after performing the operations described above.
16+
*/
17+
18+
/**
19+
*@param {number[][]} grid
20+
*@return {number}
21+
*/
22+
vardeleteGreatestValue=function(grid){
23+
for(constrowofgrid){
24+
row.sort((a,b)=>a-b);
25+
}
26+
27+
letresult=0;
28+
constcols=grid[0].length;
29+
for(letcol=cols-1;col>=0;col--){
30+
letmaxInColumn=0;
31+
for(letrow=0;row<grid.length;row++){
32+
maxInColumn=Math.max(maxInColumn,grid[row][col]);
33+
}
34+
result+=maxInColumn;
35+
}
36+
37+
returnresult;
38+
};

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp