''' 解题思路: 1、读入两个链表合成一个list再由大小到排序 2、对输出链表向尾向头赋值,引入一个临时变量next,尾部时next=None, 后续next=cur ''' # class ListNode: # def __init__(self, x): # self.val = x # self.next = None # # # @param l1 ListNode类 # @param l2 ListNode类 # @return ListNode类 # class Solution: def mergeTwoLists(self , l1 , l2 ): # write code here if l1==None and l2==None: return None tmp = [] while l1: tmp.append(l1.val) l1 = l1.next while l2: tmp.append(l2.val) l2 = l2.next tmp = sorted(tmp,reverse=1) n = len(tmp) next = None for i in range(n): cur = ListNode(tmp[i]) cur.next = next next = cur return cur