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,18 +6,18 @@
#include "../utils/common.hpp"
/* Max capacity: Greedy algorithm */
/* Maximum container capacity: greedy algorithm */
int maxCapacity(vector<int> &ht) {
// Initialize i, j to be at both ends of the array
// Initialize i and j at opposite ends of the array
int i = 0, j = ht.size() - 1;
// Initial max capacity is 0
// The initial maximum capacity is 0
int 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
int 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++;
} else {
@@ -27,13 +27,13 @@ int maxCapacity(vector<int> &ht) {
return res;
}
/* Driver Code */
/* Driver code */
int main() {
vector<int> ht = {3, 8, 5, 2, 7, 7, 3, 4};
// Greedy algorithm
int res = maxCapacity(ht);
cout << "Maximum capacity is " << res << endl;
cout << "Maximum capacity: " << res << endl;
return 0;
}