Update reverse_linked_list.py

This commit is contained in:
marina 2023-08-02 17:49:22 -07:00 committed by GitHub
parent 17ca5877bf
commit c004a953a9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -2,15 +2,15 @@
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
# author: bt3gl # author: bt3gl
class ListNode: class Node:
def __init__(self, val=0, next=None): def __init__(self, val=0, next):
self.val = val self.val = val
self.next = next self.next = next
def reverse_list(head: Optional[ListNode]) -> Optional[ListNode]: def reverse_list(head: Optional[Node]) -> Optional[Node]:
if (not head) or (not head.next): if not head or not head.next:
return head return head
new_head = reverse_list(head.next) new_head = reverse_list(head.next)