-
Notifications
You must be signed in to change notification settings - Fork 17
/
max-increase-to-keep-city-skyline.py
57 lines (44 loc) · 1.43 KB
/
max-increase-to-keep-city-skyline.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
47
48
49
50
51
52
53
54
55
56
57
import unittest
class Solution:
def maxIncreaseKeepingSkyline(self, grid: 'List[List[int]]') -> 'int':
rows_max = [0] * len(grid)
columns_max = [0] * len(grid[0])
for row in range(len(grid)):
for column in range(len(grid[0])):
if rows_max[row] < grid[row][column]:
rows_max[row] = grid[row][column]
if columns_max[column] < grid[row][column]:
columns_max[column] = grid[row][column]
result = 0
for row in range(len(grid)):
for column in range(len(grid[0])):
result += \
min(rows_max[row], columns_max[column]) - grid[row][column]
return result
class TestSolution(unittest.TestCase):
def setUp(self):
self.sol = Solution()
def test_1x1(self):
self.assertEqual(
self.sol.maxIncreaseKeepingSkyline([[1]]),
0,
)
def test_2x2(self):
self.assertEqual(
self.sol.maxIncreaseKeepingSkyline([[1, 2], [3, 4]]),
1,
)
def test_custom(self):
self.assertEqual(
self.sol.maxIncreaseKeepingSkyline(
[
[3, 0, 8, 4],
[2, 4, 5, 7],
[9, 2, 6, 3],
[0, 3, 1, 0],
]
),
35,
)
if __name__ == "__main__":
unittest.main()