Skip to content

Commit faeaa2b

Browse files
Solve : Reorder List
1 parent 16dddfa commit faeaa2b

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

reorder-list/printjin-gmailcom.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
class Solution:
2+
def reorderList(self, head):
3+
if not head:
4+
return
5+
nodes = []
6+
current = head
7+
while current:
8+
nodes.append(current)
9+
current = current.next
10+
i, j = 0, len(nodes) - 1
11+
while i < j:
12+
nodes[i].next = nodes[j]
13+
i += 1
14+
if i == j:
15+
break
16+
nodes[j].next = nodes[i]
17+
j -= 1
18+
nodes[i].next = None

0 commit comments

Comments
 (0)