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 |
반응형
'python-algorithm' 카테고리의 다른 글
leetcode 1636. Sort Array by Increasing Frequency (0) | 2024.01.09 |
---|---|
leetcode 2278. Percentage of Letter in String (0) | 2024.01.08 |
leetcode 2706. Buy Two Chocolates (0) | 2024.01.05 |
leetcode 2843. Count Symmetric Integers (0) | 2024.01.05 |
leetcode 2894. Divisible and Non-divisible Sums Difference (1) | 2024.01.05 |
댓글