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

@@ -4,23 +4,23 @@
* Author: Justin (xiefahit@gmail.com)
*/
/* Backtracking algorithm: Permutations I */
/* Backtracking: permutations I */
function backtrack(state, choices, selected, res) {
// When the state length equals the number of elements, record the solution
// Record a solution when the state length equals the number of elements
if (state.length === choices.length) {
res.push([...state]);
return;
}
// Traverse all choices
// Iterate over all choices
choices.forEach((choice, i) => {
// Pruning: do not allow repeated selection of elements
// Prune: do not choose an element more than once
if (!selected[i]) {
// Attempt: make choice, update state
// Try: make a choice and update the state
selected[i] = true;
state.push(choice);
// Proceed to the next round of selection
// Proceed to the next choice
backtrack(state, choices, selected, res);
// Backtrack: undo choice, restore to previous state
// Backtrack: undo the choice and restore the previous state
selected[i] = false;
state.pop();
}
@@ -34,7 +34,7 @@ function permutationsI(nums) {
return res;
}
// Driver Code
// Driver code
const nums = [1, 2, 3];
const res = permutationsI(nums);