@@ -54,7 +54,7 @@ class Solution {
5454 var indexStack = new Stack<Integer > ();
5555
5656 for (var i = 0 ; i < heights. length; i++ ) {
57- while (! indexStack. empty() && heights[indexStack. peek()] < heights[i]) {
57+ while (! indexStack. empty() && heights[indexStack. peek()] <= heights[i]) {
5858 var poppedIndex = indexStack. pop();
5959
6060 if (indexStack. empty()) {
@@ -84,7 +84,7 @@ class Solution:
8484 index_stack = []
8585
8686 for i, height in enumerate (heights):
87- while index_stack and heights[index_stack[- 1 ]] < height:
87+ while index_stack and heights[index_stack[- 1 ]] <= height:
8888 popped_index = index_stack.pop()
8989
9090 if not index_stack:
@@ -114,7 +114,7 @@ public:
114114 for (auto i = 0; i < heights.size(); i++) {
115115 auto previous_height = 0;
116116
117- while (!index_stack.empty() && heights[index_stack.top()] < heights[i]) {
117+ while (!index_stack.empty() && heights[index_stack.top()] <= heights[i]) {
118118 auto popped_index = index_stack.top();
119119 index_stack.pop();
120120
@@ -144,7 +144,7 @@ var trap = function (heights) {
144144 const indexStack = []
145145
146146 heights .forEach ((height , i ) => {
147- while (indexStack .length > 0 && heights[indexStack .at (- 1 )] < height) {
147+ while (indexStack .length > 0 && heights[indexStack .at (- 1 )] <= height) {
148148 const poppedIndex = indexStack .pop ()
149149
150150 if (indexStack .length === 0 ) {
@@ -175,7 +175,7 @@ public class Solution {
175175 var indexStack = new Stack <int >();
176176
177177 for (var i = 0 ; i < heights .Length ; i ++ ) {
178- while (indexStack .Count > 0 && heights [indexStack .Peek ()] < heights [i ]) {
178+ while (indexStack .Count > 0 && heights [indexStack .Peek ()] <= heights [i ]) {
179179 var poppedIndex = indexStack .Pop ();
180180
181181 if (indexStack .Count == 0 ) {
@@ -204,7 +204,7 @@ func trap(heights []int) int {
204204 indexStack := []int {}
205205
206206 for i , height := range heights {
207- for len (indexStack) > 0 && heights[indexStack[len (indexStack) - 1 ]] < height {
207+ for len (indexStack) > 0 && heights[indexStack[len (indexStack) - 1 ]] <= height {
208208 poppedIndex := indexStack[len (indexStack) - 1 ]
209209 indexStack = indexStack[:len (indexStack) - 1 ]
210210
0 commit comments