Skip to content

Instantly share code, notes, and snippets.

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