forked from dipanshu0892/Data-Structures-Algo-with-Python
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrotatelist.py
More file actions
32 lines (27 loc) · 644 Bytes
/
Copy pathrotatelist.py
File metadata and controls
32 lines (27 loc) · 644 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# Definition for singly-linked list.
# class ListNode(object):
# def __init__(self, x):
# self.val = x
# self.next = None
class Solution(object):
def reorderList(self, head):
curr=head
curr2=head
l=[]
while curr:
l.append(curr.val)
curr=curr.next
n=len(l)
j=n-1
l2=[]
i=0
while j>i:
l2.append(l[i])
l2.append(l[j])
i=i+1
j=j-1
if len(l)%2!=0:
l2.append(l[i])
for i in range(0,len(l2)):
curr2.val=l2[i]
curr2=curr2.next