mirror of
https://github.com/krahets/hello-algo.git
synced 2026-06-15 22:57:48 +08: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:
@@ -15,7 +15,7 @@ public class ListNode {
|
||||
val = x;
|
||||
}
|
||||
|
||||
/* リストを連結リストにデシリアライズ */
|
||||
/* リストを連結リストにデシリアライズする */
|
||||
public static ListNode arrToLinkedList(int[] arr) {
|
||||
ListNode dum = new ListNode(0);
|
||||
ListNode head = dum;
|
||||
@@ -25,4 +25,4 @@ public class ListNode {
|
||||
}
|
||||
return dum.next;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -19,7 +19,7 @@ class Trunk {
|
||||
};
|
||||
|
||||
public class PrintUtil {
|
||||
/* 行列を印刷 (配列) */
|
||||
/* 行列を出力する(Array) */
|
||||
public static <T> void printMatrix(T[][] matrix) {
|
||||
System.out.println("[");
|
||||
for (T[] row : matrix) {
|
||||
@@ -28,7 +28,7 @@ public class PrintUtil {
|
||||
System.out.println("]");
|
||||
}
|
||||
|
||||
/* 行列を印刷 (リスト) */
|
||||
/* 行列を出力する(List) */
|
||||
public static <T> void printMatrix(List<List<T>> matrix) {
|
||||
System.out.println("[");
|
||||
for (List<T> row : matrix) {
|
||||
@@ -37,7 +37,7 @@ public class PrintUtil {
|
||||
System.out.println("]");
|
||||
}
|
||||
|
||||
/* 連結リストを印刷 */
|
||||
/* 連結リストを出力 */
|
||||
public static void printLinkedList(ListNode head) {
|
||||
List<String> list = new ArrayList<>();
|
||||
while (head != null) {
|
||||
@@ -47,16 +47,16 @@ public class PrintUtil {
|
||||
System.out.println(String.join(" -> ", list));
|
||||
}
|
||||
|
||||
/* 二分木を印刷 */
|
||||
/* 二分木を出力 */
|
||||
public static void printTree(TreeNode root) {
|
||||
printTree(root, null, false);
|
||||
}
|
||||
|
||||
/**
|
||||
* 二分木を印刷
|
||||
* この木プリンターはTECHIE DELIGHTから借用
|
||||
* https://www.techiedelight.com/c-program-print-binary-tree/
|
||||
*/
|
||||
* 二分木を出力
|
||||
* This tree printer is borrowed from TECHIE DELIGHT
|
||||
* https://www.techiedelight.com/c-program-print-binary-tree/
|
||||
*/
|
||||
public static void printTree(TreeNode root, Trunk prev, boolean isRight) {
|
||||
if (root == null) {
|
||||
return;
|
||||
@@ -97,20 +97,20 @@ public class PrintUtil {
|
||||
System.out.print(p.str);
|
||||
}
|
||||
|
||||
/* ハッシュテーブルを印刷 */
|
||||
/* ハッシュテーブルを出力 */
|
||||
public static <K, V> void printHashMap(Map<K, V> map) {
|
||||
for (Map.Entry<K, V> kv : map.entrySet()) {
|
||||
System.out.println(kv.getKey() + " -> " + kv.getValue());
|
||||
}
|
||||
}
|
||||
|
||||
/* ヒープを印刷 (優先度キュー) */
|
||||
/* ヒープ(優先度付きキュー)を出力する */
|
||||
public static void printHeap(Queue<Integer> queue) {
|
||||
List<Integer> list = new ArrayList<>(queue);
|
||||
System.out.print("ヒープの配列表現:");
|
||||
System.out.print("ヒープの配列表現:");
|
||||
System.out.println(list);
|
||||
System.out.println("ヒープの木表現:");
|
||||
System.out.println("ヒープの木構造表現:");
|
||||
TreeNode root = TreeNode.listToTree(list);
|
||||
printTree(root);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -11,7 +11,7 @@ import java.util.*;
|
||||
/* 二分木ノードクラス */
|
||||
public class TreeNode {
|
||||
public int val; // ノード値
|
||||
public int height; // ノード高さ
|
||||
public int height; // ノードの高さ
|
||||
public TreeNode left; // 左子ノードへの参照
|
||||
public TreeNode right; // 右子ノードへの参照
|
||||
|
||||
@@ -20,23 +20,23 @@ public class TreeNode {
|
||||
val = x;
|
||||
}
|
||||
|
||||
// シリアライゼーション符号化ルールについては、次を参照:
|
||||
// シリアライズの符号化規則は以下を参照:
|
||||
// https://www.hello-algo.com/chapter_tree/array_representation_of_tree/
|
||||
// 二分木の配列表現:
|
||||
// 二分木の配列表現:
|
||||
// [1, 2, 3, 4, None, 6, 7, 8, 9, None, None, 12, None, None, 15]
|
||||
// 二分木の連結リスト表現:
|
||||
// /——— 15
|
||||
// /——— 7
|
||||
// /——— 3
|
||||
// | \——— 6
|
||||
// | \——— 12
|
||||
// 二分木の連結リスト表現:
|
||||
// /——— 15
|
||||
// /——— 7
|
||||
// /——— 3
|
||||
// | \——— 6
|
||||
// | \——— 12
|
||||
// ——— 1
|
||||
// \——— 2
|
||||
// | /——— 9
|
||||
// \——— 4
|
||||
// \——— 8
|
||||
// \——— 2
|
||||
// | /——— 9
|
||||
// \——— 4
|
||||
// \——— 8
|
||||
|
||||
/* リストを二分木にデシリアライズ:再帰的 */
|
||||
/* リストを二分木にデシリアライズする: 再帰 */
|
||||
private static TreeNode listToTreeDFS(List<Integer> arr, int i) {
|
||||
if (i < 0 || i >= arr.size() || arr.get(i) == null) {
|
||||
return null;
|
||||
@@ -47,12 +47,12 @@ public class TreeNode {
|
||||
return root;
|
||||
}
|
||||
|
||||
/* リストを二分木にデシリアライズ */
|
||||
/* リストを二分木にデシリアライズする */
|
||||
public static TreeNode listToTree(List<Integer> arr) {
|
||||
return listToTreeDFS(arr, 0);
|
||||
}
|
||||
|
||||
/* 二分木をリストにシリアライズ:再帰的 */
|
||||
/* 二分木をリストにシリアライズする: 再帰 */
|
||||
private static void treeToListDFS(TreeNode root, int i, List<Integer> res) {
|
||||
if (root == null)
|
||||
return;
|
||||
@@ -64,10 +64,10 @@ public class TreeNode {
|
||||
treeToListDFS(root.right, 2 * i + 2, res);
|
||||
}
|
||||
|
||||
/* 二分木をリストにシリアライズ */
|
||||
/* 二分木をリストにシリアライズする */
|
||||
public static List<Integer> treeToList(TreeNode root) {
|
||||
List<Integer> res = new ArrayList<>();
|
||||
treeToListDFS(root, 0, res);
|
||||
return res;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -16,7 +16,7 @@ public class Vertex {
|
||||
this.val = val;
|
||||
}
|
||||
|
||||
/* 値のリストvalsを入力し、頂点のリストvetsを返す */
|
||||
/* 値リスト vals を入力し、頂点リスト vets を返す */
|
||||
public static Vertex[] valsToVets(int[] vals) {
|
||||
Vertex[] vets = new Vertex[vals.length];
|
||||
for (int i = 0; i < vals.length; i++) {
|
||||
@@ -25,7 +25,7 @@ public class Vertex {
|
||||
return vets;
|
||||
}
|
||||
|
||||
/* 頂点のリストvetsを入力し、値のリストvalsを返す */
|
||||
/* 頂点リスト vets を入力し、値リスト vals を返す */
|
||||
public static List<Integer> vetsToVals(List<Vertex> vets) {
|
||||
List<Integer> vals = new ArrayList<>();
|
||||
for (Vertex vet : vets) {
|
||||
@@ -33,4 +33,4 @@ public class Vertex {
|
||||
}
|
||||
return vals;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user