We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 3e19cc3 commit bb5e360Copy full SHA for bb5e360
src/linked_list.py
@@ -0,0 +1,34 @@
1
+"""
2
+Linked List operations module.
3
+
4
+This module provides functionality for manipulating singly linked lists,
5
+including operations like reversing the list.
6
7
8
9
+class ListNode:
10
+ def __init__(self, val=None, next=None):
11
+ self.val = val
12
+ self.next = next
13
14
15
+def reverse_linked_list(head: ListNode) -> ListNode:
16
+ """
17
+ Reverses a singly linked list.
18
19
+ Args:
20
+ head (ListNode): The head node of the linked list
21
22
+ Returns:
23
+ ListNode: The head node of the reversed linked list
24
25
+ prev = None
26
+ current = head
27
28
+ while current is not None:
29
+ next_temp = current.next
30
+ current.next = prev
31
+ prev = current
32
+ current = next_temp
33
34
+ return prev
0 commit comments