更新双指针
This commit is contained in:
@@ -18,7 +18,7 @@ func trap(height []int) int {
|
|||||||
}
|
}
|
||||||
if height[leftP] > height[rightP] {
|
if height[leftP] > height[rightP] {
|
||||||
midres += height[leftP] - height[rightP]
|
midres += height[leftP] - height[rightP]
|
||||||
fmt.Println("result加上:", height[leftP]-height[rightP], "当前1左指针:", leftP, "当前右指针:", rightP)
|
fmt.Println("result加上:", height[leftP]-height[rightP], "当前左指针:", leftP, "当前右指针:", rightP)
|
||||||
rightP++
|
rightP++
|
||||||
} else if height[leftP] <= height[rightP] && midres != 0 {
|
} else if height[leftP] <= height[rightP] && midres != 0 {
|
||||||
result += midres
|
result += midres
|
||||||
|
|||||||
Reference in New Issue
Block a user