mirror of
https://github.com/autistic-symposium/master-algorithms-py.git
synced 2025-04-29 12:16:14 -04:00
Update reverse_linked_list.py
This commit is contained in:
parent
17ca5877bf
commit
c004a953a9
@ -2,15 +2,15 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
# author: bt3gl
|
||||
|
||||
class ListNode:
|
||||
def __init__(self, val=0, next=None):
|
||||
class Node:
|
||||
def __init__(self, val=0, next):
|
||||
self.val = val
|
||||
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
|
||||
|
||||
new_head = reverse_list(head.next)
|
||||
|
Loading…
x
Reference in New Issue
Block a user