此题题目原图来自leetcode上的trapping Rain Water
思路,先思考什么地方能装水:假如以左边第一个为基准,那只有比基准矮的才能蓄水,如何选择基准?因为是中间装水,木桶原理,最矮的是装水的基准线。所以从两边开始,每次选择较矮的为基准,只有比基准矮的装水,否则就要重新选择基准。
#include <iostream>
#include <vector>
using namespace std;
int TrappingWater(vector<int> data)
{
int left = 0;
int right = data.size()-1;
int volume = 0;
int currsmall = left;
int currheight = data[currsmall];
while (left < right)
{
if(data[left] <= data[right])
{
currsmall = left;
c