mirror of
https://github.com/krahets/hello-algo.git
synced 2026-09-01 04:47:12 +00:00
Re-translate the Japanese version (#1871)
* Retranslate Japanese docs with GPT-5.4 * Retranslate Japanese code with GPT-5.4
This commit is contained in:
@@ -0,0 +1,28 @@
|
||||
// File: max_capacity.go
|
||||
// Created Time: 2023-07-23
|
||||
// Author: Reanon (793584285@qq.com)
|
||||
|
||||
package chapter_greedy
|
||||
|
||||
import "math"
|
||||
|
||||
/* 最大容量:貪欲法 */
|
||||
func maxCapacity(ht []int) int {
|
||||
// i, j を初期化し、それぞれ配列の両端に置く
|
||||
i, j := 0, len(ht)-1
|
||||
// 初期の最大容量は 0
|
||||
res := 0
|
||||
// 2 枚の板が出会うまで貪欲選択を繰り返す
|
||||
for i < j {
|
||||
// 最大容量を更新する
|
||||
capacity := int(math.Min(float64(ht[i]), float64(ht[j]))) * (j - i)
|
||||
res = int(math.Max(float64(res), float64(capacity)))
|
||||
// 短い方を内側へ動かす
|
||||
if ht[i] < ht[j] {
|
||||
i++
|
||||
} else {
|
||||
j--
|
||||
}
|
||||
}
|
||||
return res
|
||||
}
|
||||
Reference in New Issue
Block a user