mirror of
https://github.com/autistic-symposium/master-algorithms-py.git
synced 2025-04-29 20:26:07 -04:00
Update reverse_linked_list.py
This commit is contained in:
parent
17ca5877bf
commit
c004a953a9
@ -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)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user