Created
November 7, 2013 07:05
-
-
Save deliro/7350277 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
def calculate_volume(relief): | |
left_max = 0 | |
right_max = 0 | |
left = 0 | |
right = len(relief) - 1 | |
volume = 0 | |
while left < right: | |
if relief[left] > left_max: | |
left_max = relief[left] | |
if relief[right] > right_max: | |
right_max = relief[right] | |
if left_max >= right_max: | |
volume += right_max - relief[right] | |
right -= 1 | |
else : | |
volume += left_max - relief[left] | |
left += 1 | |
return volume | |
a = [10, 9, 8, 7, 6, 5, 4] | |
print(calculate_volume(a)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment