Skip to content

Commit 8face3d

Browse files
aQuaaQua
authored andcommitted
756 finish
1 parent 2fba060 commit 8face3d

File tree

1 file changed

+16
-8
lines changed

1 file changed

+16
-8
lines changed

Algorithms/0756.pour-water/pour-water.go

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,33 +10,41 @@ func pourWater(heights []int, V int, K int) []int {
1010
return heights
1111
}
1212

13+
// 当 water 可以放在 cent 的 left 边时,返回 true
14+
// 否则,返回 false
1315
func isDroppedLeft(heights []int, center int) bool {
14-
idx := center
16+
index := center
1517
i := center
1618
for 0 <= i-1 && heights[i-1] <= heights[i] {
19+
// 出现落差,说明
20+
// i-1 是一个可行的落脚点
1721
if heights[i-1] < heights[i] {
18-
idx = i - 1
22+
index = i - 1
1923
}
2024
i--
2125
}
22-
if idx < center {
23-
heights[idx]++
26+
if index < center {
27+
heights[index]++
2428
return true
2529
}
2630
return false
2731
}
2832

33+
// 当 water 可以放在 cent 的 right 边时,返回 true
34+
// 否则,返回 false
2935
func isDroppedRight(heights []int, center int) bool {
30-
idx := center
36+
index := center
3137
i := center
3238
for i+1 < len(heights) && heights[i] >= heights[i+1] {
39+
// 出现落差,说明
40+
// i+1 是一个可行的落脚点
3341
if heights[i] > heights[i+1] {
34-
idx = i + 1
42+
index = i + 1
3543
}
3644
i++
3745
}
38-
if center < idx {
39-
heights[idx]++
46+
if center < index {
47+
heights[index]++
4048
return true
4149
}
4250
return false

0 commit comments

Comments
 (0)