Created
October 10, 2015 13:28
-
-
Save dimonb/1bb3a37b915f0d21094e 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
auto l = height.begin(), r = height.end() - 1; | |
int level = 0, water = 0; | |
while (l != r + 1) { | |
int lower = *l < *r ? *l++ : *r--; | |
level = max(level, lower); | |
water += level - lower; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment