Pour Water Posted on 2018-10-20 Descriptionhttps://leetcode.com/problems/pour-water/ Solution123456789101112131415161718192021222324252627282930313233343536class Solution {public: vector<int> pourWater(vector<int>& heights, int V, int K) { vector<int> ret = heights; if (K < 0 || K >= heights.size() ) return heights; for (int i = 0; i < V; ++i) { //Check left int index = K - 1; int minIndex = -1; while(index >= 0 && ret[index] <= ret[index + 1]) { if (ret[index] < ret[index + 1]) minIndex = index; --index; } if (minIndex != - 1) { ++ret[minIndex]; continue; } //Check right index = K + 1; minIndex = -1; while(index < ret.size() && ret[index] <= ret[index - 1]) { if (ret[index] < ret[index - 1]) minIndex = index; ++index; } if (minIndex != -1) { ++ret[minIndex]; continue; } //Stay here ++ret[K]; } return ret; }};