File tree Expand file tree Collapse file tree 1 file changed +11
-10
lines changed Expand file tree Collapse file tree 1 file changed +11
-10
lines changed Original file line number Diff line number Diff line change @@ -34,24 +34,25 @@ def trapped_rainwater(heights: tuple[int, ...]) -> int:
3434 return 0
3535 if any (h < 0 for h in heights ):
3636 raise ValueError ("No height can be negative" )
37- left ,right = 0 , len (heights )- 1
38- leftmax ,rightmax = 0 , 0
39- water = 0
40- while left < right :
37+ left , right = 0 , len (heights ) - 1
38+ leftmax , rightmax = 0 , 0
39+ water = 0
40+ while left < right :
4141 if heights [left ] < heights [right ]:
4242 if heights [left ] >= leftmax :
43- leftmax = heights [left ]
43+ leftmax = heights [left ]
4444 else :
45- water += leftmax - heights [left ]
46- left += 1
45+ water += leftmax - heights [left ]
46+ left += 1
4747 else :
4848 if heights [right ] >= rightmax :
49- rightmax = heights [right ]
49+ rightmax = heights [right ]
5050 else :
51- water += rightmax - heights [right ]
52- right -= 1
51+ water += rightmax - heights [right ]
52+ right -= 1
5353 return water
5454
55+
5556if __name__ == "__main__" :
5657 import doctest
5758
You can’t perform that action at this time.
0 commit comments