본문 바로가기
python-algorithm

leetcode 2500. Delete Greatest Value in Each Row

by 무적김두칠 2024. 1. 7.

https://leetcode.com/problems/delete-greatest-value-in-each-row/description/

 

Delete Greatest Value in Each Row - LeetCode

Can you solve this real interview question? Delete Greatest Value in Each Row - You are given an m x n matrix grid consisting of positive integers. Perform the following operation until grid becomes empty: * Delete the element with the greatest value from

leetcode.com

 

1
2
3
4
5
6
7
8
9
10
11
12
13
class Solution:
    def deleteGreatestValue(self, grid: List[List[int]]) -> int:
        m, n =len(grid), len(grid[0])
        answer = []
        for i in range(n):
            tmp = 0
            for each_row in grid:
                target = max(each_row)
                each_row.remove(target)
                tmp = max(tmp, target)
            answer.append(tmp)
        return sum(answer)
 
cs
반응형

댓글