Skip to content

Instantly share code, notes, and snippets.

@parcar
Created August 9, 2019 15:42
Show Gist options
  • Save parcar/416d3f22b0c7f2e0df87d7736887e23f to your computer and use it in GitHub Desktop.
Save parcar/416d3f22b0c7f2e0df87d7736887e23f to your computer and use it in GitHub Desktop.
class Solution(object):
def maxIncreaseKeepingSkyline(self, grid):
"""
:type grid: List[List[int]]
:rtype: int
"""
colMax = [0] * len(grid[0])
rowMax = []
for i in grid:
rowMax.append(max(i))
for jdx, j in enumerate(i):
colMax[jdx] = j if j > colMax[jdx] else colMax[jdx]
print(rowMax, colMax)
sum = 0
for idx, i in enumerate(grid):
for jdx, j in enumerate(i):
sum += min(colMax[jdx],rowMax[idx]) - j
return sum
'''
Runtime: 52 ms, faster than 91.92% of Python online submissions for Max Increase to Keep City Skyline.
Memory Usage: 11.8 MB, less than 50.00% of Python online submissions for Max Increase to Keep City Skyline.
'''
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment