/
githubmirror
/
hello-algo
Обзор
Документация
Войти
/
githubmirror
/
hello-algo
Код
Запросы
0
Пакеты
0
Релизы
0
Аналитика
Безопасность
main
ja/codes/python/modules/list_node.py
32 строки
805 B
Yudong Jin
Re-translate the Japanese version (#1871)
30 мар 2026, 02:30
Не верифицирован
30 мар 2026, 02:30
d7b2277
Код
Авторство
О чём код?
""" 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