-
Notifications
You must be signed in to change notification settings - Fork 0
/
2500.py
46 lines (30 loc) · 1.08 KB
/
2500.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
from typing import List
import unittest
class Solution:
def deleteGreatestValue(self, grid: List[List[int]]) -> int:
count = 0
for i in range(len(grid)):
grid[i] = list(sorted(grid[i]))
if len(grid) == 0 or len(grid[0]) == 0:
return 0
i = len(grid)
j = len(grid[0]) - 1
while j >= 0:
greatest = 0
for r in range(i):
if grid[r][j] > greatest:
greatest = grid[r][j]
count += greatest
j -= 1
return count
class Test(unittest.TestCase):
def test_first(self):
self.assertEqual(Solution().deleteGreatestValue(grid=[[1, 2, 4], [3, 3, 1]]), 8)
def test_second(self):
self.assertEqual(Solution().deleteGreatestValue(grid=[[10]]), 10)
def test_third(self):
self.assertEqual(Solution().deleteGreatestValue(grid=[[10, 1, 2]]), 13)
def test_fourth(self):
self.assertEqual(Solution().deleteGreatestValue(grid=[[1, 2, 3], [1, 3, 5]]), 9)
if __name__ == '__main__':
unittest.main()