标签:bsp init 时间 color fas ima none 图片 表拆分
class Node: def __init__(self,value): self.val = value self.next = None def mergeList(l1,l2): if not l1 or not l2: return l1 if l1 else l2 cur1 , cur2 = l1 , l2 head = cur1 if cur1.val < cur2.val else cur2 cur = None while cur1 and cur2: tail = cur cur = cur1 if cur1.val < cur2.val else cur2 cur1 = cur1.next if cur == cur1 else cur1 cur2 = cur2.next if cur == cur2 else cur2 if tail: tail.next = cur tail.next.next = cur1 if cur1 else cur2 return head head = Node(1) p = head for i in range(2,4): p.next = Node(i) p = p.next head1 = Node(1) p = head1 for i in range(2,5): p.next = Node(i) p = p.next mergeList(head,head1)
class Node: def __init__(self,value): self.val = value self.next = None #拆分链表 def relocate(head): if not head or not head.next: return head slow = head fast = head.next while fast.next and fast.next.next: slow = slow.next fast = fast.next.next right = slow.next slow.next = None mergeLR(head,right) #合并链表 def mergeLR(left,right): if not left or not right: return left if left else right head = left cur =head while left: left = left.next cur.next = right cur = cur.next right = right.next cur.next = left cur = cur.next return head head = Node(1) p = head for i in range(2,9): p.next = Node(i) p = p.next res = relocate(head)
标签:bsp init 时间 color fas ima none 图片 表拆分
原文地址:https://www.cnblogs.com/Lee-yl/p/9785703.html