mirror of
https://github.com/krahets/hello-algo.git
synced 2026-11-05 20:52:21 +08:00
Retranslate the complete Japanese online edition from Chinese (#2008)
* Retranslate the complete Japanese online edition from Chinese * Fit Japanese homepage labels and localize heading permalinks * Point Japanese contribution instructions to the Japanese preview * Replace locale conditionals with multilingual UI tables
This commit is contained in:
@@ -6,7 +6,7 @@
|
||||
|
||||
package utils;
|
||||
|
||||
/* 連結リストノード */
|
||||
/* 連結リストのノード */
|
||||
public class ListNode {
|
||||
public int val;
|
||||
public ListNode next;
|
||||
@@ -15,7 +15,7 @@ public class ListNode {
|
||||
val = x;
|
||||
}
|
||||
|
||||
/* リストを連結リストにデシリアライズする */
|
||||
/* リストをデシリアライズして連結リストにする */
|
||||
public static ListNode arrToLinkedList(int[] arr) {
|
||||
ListNode dum = new ListNode(0);
|
||||
ListNode head = dum;
|
||||
|
||||
@@ -19,7 +19,7 @@ class Trunk {
|
||||
};
|
||||
|
||||
public class PrintUtil {
|
||||
/* 行列を出力する(Array) */
|
||||
/* 行列を表示する(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) */
|
||||
/* 行列を表示する(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);
|
||||
}
|
||||
|
||||
/**
|
||||
* 二分木を出力
|
||||
* This tree printer is borrowed from TECHIE DELIGHT
|
||||
* https://www.techiedelight.com/c-program-print-binary-tree/
|
||||
*/
|
||||
* 二分木を表示する
|
||||
* この木の表示処理は 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,14 +97,14 @@ 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("ヒープの配列表現:");
|
||||
|
||||
@@ -8,35 +8,35 @@ package utils;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
/* 二分木ノードクラス */
|
||||
/* 二分木のノードクラス */
|
||||
public class TreeNode {
|
||||
public int val; // ノード値
|
||||
public int val; // ノードの値
|
||||
public int height; // ノードの高さ
|
||||
public TreeNode left; // 左子ノードへの参照
|
||||
public TreeNode right; // 右子ノードへの参照
|
||||
public TreeNode left; // 左の子ノードへの参照
|
||||
public TreeNode right; // 右の子ノードへの参照
|
||||
|
||||
/* コンストラクタ */
|
||||
public TreeNode(int x) {
|
||||
val = x;
|
||||
}
|
||||
|
||||
// シリアライズの符号化規則は以下を参照:
|
||||
// https://www.hello-algo.com/chapter_tree/array_representation_of_tree/
|
||||
// 二分木の配列表現:
|
||||
// シリアライズの符号化規則は次を参照:
|
||||
// https://www.hello-algo.com/ja/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,7 +64,7 @@ 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);
|
||||
|
||||
@@ -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) {
|
||||
|
||||
Reference in New Issue
Block a user