mirror of
https://github.com/krahets/hello-algo.git
synced 2026-11-03 19:52:01 +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:
@@ -1,8 +1,8 @@
|
||||
# Follow the PEP 585 - Type Hinting Generics In Standard Collections
|
||||
# PEP 585「標準コレクションにおける型ヒント用のジェネリクス」に従う
|
||||
# https://peps.python.org/pep-0585/
|
||||
from __future__ import annotations
|
||||
|
||||
# Import common libs here to simplify the code by `from module import *`
|
||||
# 共通ライブラリをここで読み込み、`from module import *` によりコードを簡潔にする
|
||||
from .list_node import (
|
||||
ListNode,
|
||||
list_to_linked_list,
|
||||
|
||||
@@ -6,15 +6,15 @@ Author: krahets ([email protected])
|
||||
|
||||
|
||||
class ListNode:
|
||||
"""連結リストノードクラス"""
|
||||
"""連結リストのノードクラス"""
|
||||
|
||||
def __init__(self, val: int):
|
||||
self.val: int = val # ノード値
|
||||
self.val: int = val # ノードの値
|
||||
self.next: ListNode | None = None # 後続ノードへの参照
|
||||
|
||||
|
||||
def list_to_linked_list(arr: list[int]) -> ListNode | None:
|
||||
"""リストを連結リストにデシリアライズする"""
|
||||
"""リストをデシリアライズして連結リストにする"""
|
||||
dum = head = ListNode(0)
|
||||
for a in arr:
|
||||
node = ListNode(a)
|
||||
@@ -24,7 +24,7 @@ def list_to_linked_list(arr: list[int]) -> ListNode | None:
|
||||
|
||||
|
||||
def linked_list_to_list(head: ListNode | None) -> list[int]:
|
||||
"""連結リストをリストにシリアライズ"""
|
||||
"""連結リストをシリアライズしてリストにする"""
|
||||
arr: list[int] = []
|
||||
while head:
|
||||
arr.append(head.val)
|
||||
|
||||
@@ -9,7 +9,7 @@ from .list_node import ListNode, linked_list_to_list
|
||||
|
||||
|
||||
def print_matrix(mat: list[list[int]]):
|
||||
"""行列を出力する"""
|
||||
"""行列を表示する"""
|
||||
s = []
|
||||
for arr in mat:
|
||||
s.append(" " + str(arr))
|
||||
@@ -17,7 +17,7 @@ def print_matrix(mat: list[list[int]]):
|
||||
|
||||
|
||||
def print_linked_list(head: ListNode | None):
|
||||
"""連結リストを出力"""
|
||||
"""連結リストを表示する"""
|
||||
arr: list[int] = linked_list_to_list(head)
|
||||
print(" -> ".join([str(a) for a in arr]))
|
||||
|
||||
@@ -39,10 +39,10 @@ def print_tree(
|
||||
root: TreeNode | None, prev: Trunk | None = None, is_right: bool = 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/
|
||||
"""
|
||||
if root is None:
|
||||
return
|
||||
|
||||
@@ -68,14 +68,14 @@ https://www.techiedelight.com/c-program-print-binary-tree/
|
||||
|
||||
|
||||
def print_dict(hmap: dict):
|
||||
"""辞書を出力"""
|
||||
"""辞書を表示する"""
|
||||
for key, value in hmap.items():
|
||||
print(key, "->", value)
|
||||
|
||||
|
||||
def print_heap(heap: list[int]):
|
||||
"""ヒープを出力"""
|
||||
"""ヒープを表示する"""
|
||||
print("ヒープの配列表現:", heap)
|
||||
print("ヒープの木構造表示:")
|
||||
print("ヒープの木構造表現:")
|
||||
root: TreeNode | None = list_to_tree(heap)
|
||||
print_tree(root)
|
||||
|
||||
@@ -8,34 +8,34 @@ from collections import deque
|
||||
|
||||
|
||||
class TreeNode:
|
||||
"""二分木ノードクラス"""
|
||||
"""二分木のノードクラス"""
|
||||
|
||||
def __init__(self, val: int = 0):
|
||||
self.val: int = val # ノード値
|
||||
self.val: int = val # ノードの値
|
||||
self.height: int = 0 # ノードの高さ
|
||||
self.left: TreeNode | None = None # 左子ノードへの参照
|
||||
self.right: TreeNode | None = None # 右子ノードへの参照
|
||||
self.left: TreeNode | None = None # 左の子ノードへの参照
|
||||
self.right: TreeNode | None = None # 右の子ノードへの参照
|
||||
|
||||
# シリアライズの符号化規則は以下を参照:
|
||||
# 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
|
||||
|
||||
|
||||
def list_to_tree_dfs(arr: list[int], i: int) -> TreeNode | None:
|
||||
"""リストを二分木にデシリアライズする: 再帰"""
|
||||
# 添字が配列長を超えるか、対応する要素が None なら、None を返す
|
||||
"""リストから二分木へデシリアライズ:再帰"""
|
||||
# 添字が配列の長さを超えるか、対応要素が None なら None を返す
|
||||
if i < 0 or i >= len(arr) or arr[i] is None:
|
||||
return None
|
||||
# 現在のノードを構築する
|
||||
@@ -47,12 +47,12 @@ def list_to_tree_dfs(arr: list[int], i: int) -> TreeNode | None:
|
||||
|
||||
|
||||
def list_to_tree(arr: list[int]) -> TreeNode | None:
|
||||
"""リストを二分木にデシリアライズする"""
|
||||
"""リストから二分木へデシリアライズ"""
|
||||
return list_to_tree_dfs(arr, 0)
|
||||
|
||||
|
||||
def tree_to_list_dfs(root: TreeNode, i: int, res: list[int]) -> list[int]:
|
||||
"""二分木をリストにシリアライズする: 再帰"""
|
||||
"""二分木をシリアライズしてリストにする:再帰"""
|
||||
if root is None:
|
||||
return
|
||||
if i >= len(res):
|
||||
@@ -63,7 +63,7 @@ def tree_to_list_dfs(root: TreeNode, i: int, res: list[int]) -> list[int]:
|
||||
|
||||
|
||||
def tree_to_list(root: TreeNode | None) -> list[int]:
|
||||
"""二分木をリストにシリアライズする"""
|
||||
"""二分木をシリアライズしてリストにする"""
|
||||
res = []
|
||||
tree_to_list_dfs(root, 0, res)
|
||||
return res
|
||||
|
||||
@@ -11,10 +11,10 @@ class Vertex:
|
||||
|
||||
|
||||
def vals_to_vets(vals: list[int]) -> list["Vertex"]:
|
||||
"""値リスト vals を入力し、頂点リスト vets を返す"""
|
||||
"""値のリスト vals を入力し、頂点のリスト vets を返す"""
|
||||
return [Vertex(val) for val in vals]
|
||||
|
||||
|
||||
def vets_to_vals(vets: list["Vertex"]) -> list[int]:
|
||||
"""頂点リスト vets を入力し、値リスト vals を返す"""
|
||||
"""頂点のリスト vets を入力し、値のリスト vals を返す"""
|
||||
return [vet.val for vet in vets]
|
||||
|
||||
Reference in New Issue
Block a user