Skip to content

Latest commit

 

History

History
34 lines (25 loc) · 600 Bytes

2500. Delete Greatest Value in Each Row.md

File metadata and controls

34 lines (25 loc) · 600 Bytes

Solution

class Solution:
    def deleteGreatestValue(self, grid: List[List[int]]) -> int:
        
        m=0
        n=len(grid[0])
        while n!=0:
            l=[]
            for i in grid:
                i.sort()

                l.append(i[-1])
                i.pop(-1)
            
            l.sort()
            m=m+l[-1]
            n=n-1

        return m

Low Run-Time solution:

for i in grid:
    i.sort()

for g in zip(*grid):  # g is a list/tuple of column elements
    m+=max(g)         # maximum element in g, i.e. maximum value in that column

return m