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:
Yudong Jin
2026-03-30 07:30:15 +08:00
committed by GitHub
parent fe6443235b
commit d7b2277d2b
1444 changed files with 83312 additions and 8363 deletions

View File

@@ -9,9 +9,9 @@ package chapter_backtracking;
import java.util.*;
public class permutations_ii {
/* バックトラッキングアルゴリズム:順列 II */
/* バックトラッキング:順列 II */
static void backtrack(List<Integer> state, int[] choices, boolean[] selected, List<List<Integer>> res) {
// 状態の長さが要素数等しくなったら、解を記録
// 状態の長さが要素数等しければ、解を記録
if (state.size() == choices.length) {
res.add(new ArrayList<Integer>(state));
return;
@@ -20,22 +20,22 @@ public class permutations_ii {
Set<Integer> duplicated = new HashSet<Integer>();
for (int i = 0; i < choices.length; i++) {
int choice = choices[i];
// 剪定:要素の重複選択を許可せず、等しい要素の重複選択も許可しない
// 枝刈り:要素の重複選択を許可せず、同値要素の重複選択も許可しない
if (!selected[i] && !duplicated.contains(choice)) {
// 試行選択を行い、状態を更新
duplicated.add(choice); // 選択された要素値を記録
// 試行: 選択を行い、状態を更新
duplicated.add(choice); // 選択済みの要素値を記録
selected[i] = true;
state.add(choice);
// 次のラウンドの選択進む
// 次の選択進む
backtrack(state, choices, selected, res);
// 回退:選択を取り消し、前の状態に復元
// バックトラック:選択を取り消し、前の状態に戻す
selected[i] = false;
state.remove(state.size() - 1);
}
}
}
/* 順列 II */
/* 順列 II */
static List<List<Integer>> permutationsII(int[] nums) {
List<List<Integer>> res = new ArrayList<List<Integer>>();
backtrack(new ArrayList<Integer>(), nums, new boolean[nums.length], res);
@@ -50,4 +50,4 @@ public class permutations_ii {
System.out.println("入力配列 nums = " + Arrays.toString(nums));
System.out.println("すべての順列 res = " + res);
}
}
}