[LeetCode]#2500. Delete Greatest Value in Each Row

Environment: Python 3.8

Key technique: for, max

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 each row. If multiple such elements exist, delete any of them.
  • Add the maximum of deleted elements to the answer.

Note that the number of columns decreases by one after each operation.

Return the answer after performing the operations described above.

Example 1:

Analysis:

  1. Find local max value and find global max value in each row.
  2. Remove local max value in each row.
  3. Summarize all global max value in each for loop.
  4. Return summary.

Solution:

Submissions:

Reference:

https://leetcode.com/problems/delete-greatest-value-in-each-row/solutions/2899409/python-easy-solution/

--

--

Interesting in any computer science.

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store