Created
March 31, 2022 22:10
-
-
Save ThomasHigginson/75dbe74a8ec1c50807b475bd0a65ca61 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
maxLefts, maxRights = [0] * len(height), [0] * len(height) | |
# Maxs set to edges | |
maxLefts[0] = height[0] | |
maxRights[len(height)-1] = height[len(height)-1] | |
i, j = 1, len(height)-2 | |
while i < len(height): | |
maxLefts[i] = max(maxLefts[i-1], height[i]) # Check this height to max height to left | |
maxRights[j] = max(maxRights[j+1], height[j]) # Check this height to max height to right | |
i += 1 | |
j -= 1 | |
# ... and now we have the max height to the left and right for each element |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment