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 b42cc9e commit 6c45667Copy full SHA for 6c45667
reorder-list/hu6r1s.py
@@ -0,0 +1,26 @@
1
+# Definition for singly-linked list.
2
+# class ListNode:
3
+# def __init__(self, val=0, next=None):
4
+# self.val = val
5
+# self.next = next
6
+class Solution:
7
+ def reorderList(self, head: Optional[ListNode]) -> None:
8
+ """
9
+ Do not return anything, modify head in-place instead.
10
11
+ stack = []
12
+ node = head
13
+ while node:
14
+ stack.append(node)
15
+ node = node.next
16
+
17
+ node = dummy = ListNode(-1)
18
+ for i in range(len(stack)):
19
+ if i % 2:
20
+ node.next = stack.pop()
21
+ else:
22
+ node.next = head
23
+ head = head.next
24
25
+ node.next = None
26
+ return dummy.next
0 commit comments