feat(ko): add the Korean online edition (#2006)

* feat(ko): add the complete Korean online edition

* Use UTF-8 for Python CI output on Windows

* Remove print-book promotion from the Korean site

* fix(ko): preserve emphasis before Korean particles
This commit is contained in:
Yudong Jin
2026-10-29 03:46:43 +08:00
committed by GitHub
parent 71a773df64
commit 2f561d3d51
2072 changed files with 110884 additions and 102 deletions
+19
View File
@@ -0,0 +1,19 @@
# PEP 585(표준 컬렉션의 제네릭 타입 힌트)를 따른다
# https://peps.python.org/pep-0585/
from __future__ import annotations
# `from module import *`로 코드를 간소화할 수 있도록 공통 라이브러리를 이곳에서 임포트한다
from .list_node import (
ListNode,
list_to_linked_list,
linked_list_to_list,
)
from .tree_node import TreeNode, list_to_tree, tree_to_list
from .vertex import Vertex, vals_to_vets, vets_to_vals
from .print_util import (
print_matrix,
print_linked_list,
print_tree,
print_dict,
print_heap,
)
+32
View File
@@ -0,0 +1,32 @@
"""
File: list_node.py
Created Time: 2021-12-11
Author: krahets ([email protected])
"""
class ListNode:
"""연결 리스트 노드 클래스"""
def __init__(self, val: int):
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)
head.next = node
head = head.next
return dum.next
def linked_list_to_list(head: ListNode | None) -> list[int]:
"""연결 리스트를 리스트로 직렬화"""
arr: list[int] = []
while head:
arr.append(head.val)
head = head.next
return arr
+81
View File
@@ -0,0 +1,81 @@
"""
File: print_util.py
Created Time: 2021-12-11
Author: krahets ([email protected]), msk397 ([email protected])
"""
from .tree_node import TreeNode, list_to_tree
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))
print("[\n" + ",\n".join(s) + "\n]")
def print_linked_list(head: ListNode | None):
"""연결 리스트 출력"""
arr: list[int] = linked_list_to_list(head)
print(" -> ".join([str(a) for a in arr]))
class Trunk:
def __init__(self, prev, string: str | None = None):
self.prev = prev
self.str = string
def show_trunks(p: Trunk | None):
if p is None:
return
show_trunks(p.prev)
print(p.str, end="")
def print_tree(
root: TreeNode | None, prev: Trunk | None = None, is_right: bool = False
):
"""
이진 트리 출력
이 트리 출력 코드는 TECHIE DELIGHT에서 가져왔다
https://www.techiedelight.com/c-program-print-binary-tree/
"""
if root is None:
return
prev_str = " "
trunk = Trunk(prev, prev_str)
print_tree(root.right, trunk, True)
if prev is None:
trunk.str = "———"
elif is_right:
trunk.str = "/———"
prev_str = " |"
else:
trunk.str = "\———"
prev.str = prev_str
show_trunks(trunk)
print(" " + str(root.val))
if prev:
prev.str = prev_str
trunk.str = " |"
print_tree(root.left, trunk, False)
def print_dict(hmap: dict):
"""딕셔너리 출력"""
for key, value in hmap.items():
print(key, "->", value)
def print_heap(heap: list[int]):
"""힙 출력"""
print("힙의 배열 표현:", heap)
print("힙의 트리 표현:")
root: TreeNode | None = list_to_tree(heap)
print_tree(root)
+69
View File
@@ -0,0 +1,69 @@
"""
File: tree_node.py
Created Time: 2021-12-11
Author: krahets ([email protected])
"""
from collections import deque
class TreeNode:
"""이진 트리 노드 클래스"""
def __init__(self, val: int = 0):
self.val: int = val # 노드 값
self.height: int = 0 # 노드 높이
self.left: TreeNode | None = None # 왼쪽 자식 노드 참조
self.right: TreeNode | None = None # 오른쪽 자식 노드 참조
# 직렬화 인코딩 규칙은 다음을 참고한다:
# https://www.hello-algo.com/ko/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
# ——— 1
# \——— 2
# | /——— 9
# \——— 4
# \——— 8
def list_to_tree_dfs(arr: list[int], i: int) -> TreeNode | None:
"""리스트를 이진 트리로 역직렬화: 재귀"""
# 인덱스가 배열 길이를 벗어나거나 해당 원소가 None이면 None을 반환한다
if i < 0 or i >= len(arr) or arr[i] is None:
return None
# 현재 노드를 생성한다
root = TreeNode(arr[i])
# 왼쪽과 오른쪽 서브트리를 재귀적으로 구성한다
root.left = list_to_tree_dfs(arr, 2 * i + 1)
root.right = list_to_tree_dfs(arr, 2 * i + 2)
return root
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):
res += [None] * (i - len(res) + 1)
res[i] = root.val
tree_to_list_dfs(root.left, 2 * i + 1, res)
tree_to_list_dfs(root.right, 2 * i + 2, res)
def tree_to_list(root: TreeNode | None) -> list[int]:
"""이진 트리를 리스트로 직렬화"""
res = []
tree_to_list_dfs(root, 0, res)
return res
+20
View File
@@ -0,0 +1,20 @@
# File: vertex.py
# Created Time: 2023-02-23
# Author: krahets ([email protected])
class Vertex:
"""정점 클래스"""
def __init__(self, val: int):
self.val = val
def vals_to_vets(vals: list[int]) -> list["Vertex"]:
"""값의 리스트 vals를 입력받아 정점 리스트 vets 반환"""
return [Vertex(val) for val in vals]
def vets_to_vals(vets: list["Vertex"]) -> list[int]:
"""정점 리스트 vets를 입력받아 값의 리스트 vals 반환"""
return [vet.val for vet in vets]