Retranslate the complete English edition from Simplified Chinese (#2010)

* Retranslate the complete English edition from Simplified Chinese

* Polish three English explanations after reader-focused review
This commit is contained in:
Yudong Jin
2026-10-31 03:35:51 +08:00
committed by GitHub
parent ef46e2ed95
commit 14c314c08c
1502 changed files with 29459 additions and 23517 deletions

View File

@@ -6,17 +6,17 @@ Author: krahets (krahets@163.com)
def max_capacity(ht: list[int]) -> int:
"""Max capacity: Greedy algorithm"""
# Initialize i, j to be at both ends of the array
"""Maximum container capacity: greedy algorithm"""
# Initialize i and j at opposite ends of the array
i, j = 0, len(ht) - 1
# Initial max capacity is 0
# The initial maximum capacity is 0
res = 0
# Loop for greedy selection until the two boards meet
# Repeatedly make greedy choices until the two sides meet
while i < j:
# Update max capacity
# Update the maximum capacity
cap = min(ht[i], ht[j]) * (j - i)
res = max(res, cap)
# Move the shorter board inward
# Move the shorter side inward
if ht[i] < ht[j]:
i += 1
else:
@@ -24,10 +24,10 @@ def max_capacity(ht: list[int]) -> int:
return res
"""Driver Code"""
"""Driver code"""
if __name__ == "__main__":
ht = [3, 8, 5, 2, 7, 7, 3, 4]
# Greedy algorithm
res = max_capacity(ht)
print(f"Max capacity is {res}")
print(f"Maximum capacity: {res}")