mirror of
https://github.com/krahets/hello-algo.git
synced 2025-11-05 14:45:55 +08:00
* docs: add Japanese documents (`ja/docs`) * docs: add Japanese documents (`ja/codes`) * docs: add Japanese documents * Remove pythontutor blocks in ja/ * Add an empty at the end of each markdown file. * Add the missing figures (use the English version temporarily). * Add index.md for Japanese version. * Add index.html for Japanese version. * Add missing index.assets * Fix backtracking_algorithm.md for Japanese version. * Add avatar_eltociear.jpg. Fix image links on the Japanese landing page. * Add the Japanese banner. --------- Co-authored-by: krahets <krahets@163.com>
32 lines
804 B
Python
32 lines
804 B
Python
"""
|
|
File: list_node.py
|
|
Created Time: 2021-12-11
|
|
Author: krahets (krahets@163.com)
|
|
"""
|
|
|
|
|
|
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 |