修改目录名称

This commit is contained in:
2025-08-19 03:50:15 +08:00
parent 98a0c7d04e
commit 2eb2d2bedc
8 changed files with 167 additions and 0 deletions

View File

@@ -0,0 +1,33 @@
package main
import "fmt"
func main() {
resule := trap([]int{4, 2, 0, 3, 2, 5})
fmt.Println("最大接水数为:", resule)
}
func trap(height []int) int {
leftP := 0
rightP := 1
result := 0
midres := 0
for {
if leftP > len(height)-1 || rightP > len(height)-1 {
break
}
if height[leftP] > height[rightP] {
midres += height[leftP] - height[rightP]
fmt.Println("result加上:", height[leftP]-height[rightP], "当前左指针:", leftP, "当前右指针:", rightP)
rightP++
} else if height[leftP] <= height[rightP] && midres != 0 {
result += midres
leftP = rightP
rightP = leftP + 1
} else {
leftP++
rightP = leftP + 1
}
}
return result
}