Skip to content

Instantly share code, notes, and snippets.

@dimonb
Created October 10, 2015 13:28
Show Gist options
  • Save dimonb/13067e1794f6420a1ed1 to your computer and use it in GitHub Desktop.
Save dimonb/13067e1794f6420a1ed1 to your computer and use it in GitHub Desktop.
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