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 416c12e commit b701aa3Copy full SHA for b701aa3
reverse_linked_list.py
@@ -0,0 +1,15 @@
1
+# Write a function that takes in the head of a Singly Linked List
2
+# (assume that the list has at least 1 node; in other words, the head will never be a null value).
3
+# The function should reverse the list and return its new head. Note that every node in the Singly Linked List
4
+# has a "value" property storing its value as well as a "next" property pointing to the next node in the list
5
+# or None (null) if it is the tail of the list.
6
+
7
8
+def reverseLinkedList(head):
9
+ p1, p2 = None, head
10
+ while p2:
11
+ p3 = p2.next
12
+ p2.next = p1
13
+ p1 = p2
14
+ p2 = p3
15
+ return p1
0 commit comments