慢慢找到对链表的感觉,加油保持前进呀哈哈哈哈!!!!
# Definition for singly-linked list. # class ListNode(object): # def __init__(self, x): # self.val = x # self.next = None class Solution(object): def partition(self, head, x): """ :type head: ListNode :type x: int :rtype: ListNode """ if not head: return a=ListNode(-1) a.next=head p=head r=p q=p.next if p.val>=x: p=a while q: if q.val>=x: q=q.next r=r.next else: if q==p.next: p=p.next r=r.next q=q.next else: r.next=q.next q.next=p.next p.next=q p=q q=r.next return a.next
原文:https://www.cnblogs.com/taoyuxin/p/11745603.html