Format python codes with black. (#453)

This commit is contained in:
Yudong Jin
2023-04-09 05:05:35 +08:00
committed by GitHub
parent 1c8b7ef559
commit 5ddcb60825
45 changed files with 656 additions and 456 deletions

View File

@ -4,14 +4,17 @@ Created Time: 2021-12-11
Author: Krahets (krahets@163.com)
"""
class ListNode:
""" Definition for a singly-linked list node """
"""Definition for a singly-linked list node"""
def __init__(self, val: int):
self.val: int = val # 节点值
self.next: ListNode | None = None # 后继节点引用
self.val: int = val # 节点值
self.next: ListNode | None = None # 后继节点引用
def list_to_linked_list(arr: list[int]) -> ListNode | None:
""" Generate a linked list with a list """
"""Generate a linked list with a list"""
dum = head = ListNode(0)
for a in arr:
node = ListNode(a)
@ -19,16 +22,18 @@ def list_to_linked_list(arr: list[int]) -> ListNode | None:
head = head.next
return dum.next
def linked_list_to_list(head: ListNode | None) -> list[int]:
""" Serialize a linked list into an array """
"""Serialize a linked list into an array"""
arr: list[int] = []
while head:
arr.append(head.val)
head = head.next
return arr
def get_list_node(head: ListNode | None, val: int) -> ListNode | None:
""" Get a list node with specific value from a linked list """
"""Get a list node with specific value from a linked list"""
while head and head.val != val:
head = head.next
return head