[leetcode]#21. Merge Two Sorted Lists

来源:互联网 发布:淘宝花呗开通条件 编辑:程序博客网 时间:2024/06/18 05:39
  • 按顺序拼接两个已排序的链表
class Solution(object):    def mergeTwoLists(self, l1, l2):        ret = ListNode(0)        if l1 == None:            return l2        if l2 == None:            return l1        if l1.val < l2.val:            ret = l1            ret.next = self.mergeTwoLists(l1.next,l2)        else:            ret = l2            ret.next = self.mergeTwoLists(l2.next,l1)        return ret
原创粉丝点击