# Definition for singly-linked list.
# class ListNode:
# def __init__(self, x):
# self.val = x
# self.next = None
class Solution:
def partition(self, head, x):
"""
:type head: ListNode
:type x: int
:rtype: ListNode
"""
small=ListNode('x')
large=ListNode('x')
res=small
mid=large
while(head):
if(head.val<x):
small.next=head
small=small.next
else:
large.next=head
large=large.next
head=head.next
large.next=None
small.next=mid.next
return res.next
Leetcode 86. Partition List
最新推荐文章于 2019-01-18 06:39:35 发布