Files
hello-algo/ko/codes/python/modules/list_node.py
T
Yudong Jin 2f561d3d51 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
2026-10-29 03:46:43 +08:00

33 lines
778 B
Python

"""
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