mirror of
https://github.com/krahets/hello-algo.git
synced 2026-07-01 01:54:24 +00:00
Add ru version (#1865)
* Add Russian docs site baseline * Add Russian localized codebase * Polish Russian code wording * Update ru code translation. * Update code translation and chapter covers. * Fix pythontutor extraction. * Add README and landing page. * placeholder of profiles * Use figures of English version * Remove chapter paperbook
This commit is contained in:
@@ -0,0 +1,32 @@
|
||||
"""
|
||||
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
|
||||
Reference in New Issue
Block a user