Skip to content

Commit 924d004

Browse files
committed
Update solution 086 [Python3]
1 parent 65fdb86 commit 924d004

File tree

1 file changed

+30
-0
lines changed

1 file changed

+30
-0
lines changed
+30
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
# Definition for singly-linked list.
2+
# class ListNode:
3+
# def __init__(self, x):
4+
# self.val = x
5+
# self.next = None
6+
7+
class Solution:
8+
def partition(self, head, x):
9+
"""
10+
:type head: ListNode
11+
:type x: int
12+
:rtype: ListNode
13+
"""
14+
leftDummy=ListNode(-1)
15+
rightDummy=ListNode(-1)
16+
leftCur=leftDummy
17+
rightCur=rightDummy
18+
19+
while head:
20+
if head.val<x:
21+
leftCur.next=head
22+
leftCur=leftCur.next
23+
else:
24+
rightCur.next=head
25+
rightCur=rightCur.next
26+
head=head.next
27+
28+
leftCur.next=rightDummy.next
29+
rightCur.next=None
30+
return leftDummy.next

0 commit comments

Comments
 (0)