剑指offer python版 合并两个排序的链表
class ListNode(object): def __init__(self,x): self.val=x self.next=None class Link(object): def __init__(self,values=None): self.nodes=self.set_link(values) if values else None def get_link(self): return self.nodes def set_link(self,values): if not values : return False head=ListNode(0) move=head try: for i in values: tmp=ListNode(i) move.next=tmp move=move.next except Exception as e: print(e) return head.next def aa(head1,head2): if not head1: return head2 if not head2: return head1 if head1.val<=head2.val: ret=head1 ret.next=aa(head1.next,head2) if head1.val>head2.val: ret=head2 ret.next=aa(head1,head2.next) return ret a=Link([1,2,3,3,4,5,6,7]) b=a.get_link() c=Link([5,6,7,8,9,10]) d=c.get_link() q=aa(b,d) while q: print(q.val) q=q.next