mirror of
https://github.com/autistic-symposium/master-algorithms-py.git
synced 2025-04-29 12:16:14 -04:00
21 lines
445 B
Python
21 lines
445 B
Python
#!/usr/bin/env python3
|
|
# -*- coding: utf-8 -*-
|
|
# author: bt3gl
|
|
|
|
class Node:
|
|
def __init__(self, val=0, next):
|
|
self.val = val
|
|
self.next = next
|
|
|
|
|
|
def reverse_list(head: Optional[Node]) -> Optional[Node]:
|
|
|
|
if not head or not head.next:
|
|
return head
|
|
|
|
new_head = reverse_list(head.next)
|
|
head.next.next = head
|
|
head.next = None
|
|
|
|
return new_head
|