-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPartitionList.py
More file actions
45 lines (38 loc) · 762 Bytes
/
PartitionList.py
File metadata and controls
45 lines (38 loc) · 762 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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
class ListNode:
def __init__(self, val=0, next=None):
self.val = val
self.next = next
numbers=[5]
dumyroot = ListNode(0)
head=dumyroot
for num in numbers:
head.next=ListNode(num)
head=head.next
head=dumyroot.next
x=4
ptr1=head
prev=ListNode(0)
prev.next=ptr1
pivot=None
h=False
while ptr1:
if not pivot and ptr1.val>=x:
pivot = prev
if head==ptr1:
head=pivot
h=True
ptr1=ptr1.next
prev=prev.next
continue
if pivot and ptr1.val<x:
prev.next=ptr1.next
ptr1.next=pivot.next
pivot.next=ptr1
pivot=pivot.next
ptr1=prev.next
continue
ptr1=ptr1.next
prev=prev.next
if h:
print (head.next)
print (head)