Blog Domain name: Http://www.xnerv.wang
Original title page: https://oj.leetcode.com/problems/merge-two-sorted-lists/
Topic Type:
Difficulty Evaluation: ★
This article address: http://blog.csdn.net/nerv3x3/article/details/3465680
Merge two sorted linked lists and return it as a new list.
Combining two sequential lists, common data structure exercises during college.
Class Solution:
# @param two listnodes
# @return a listnode
def mergetwolists (self, L1, L2):
If None = L1 And none = L2: Return
none
elif none = L1: Return
L2
elif none = L2: Return
l1 new_list
= List Node (0)
cur = new_list
node1 = L1
node2 = L2 while
None!= Node1 and none!= Node2:
if Node1.val < node2.val:
cur.next = node1
Node1 = node1.next
else:
cur.next = node2 Node2
= node2.next< C20/>cur = Cur.next
if None!= node1:
cur.next = Node1
else:
cur.next = node2 return
new_ List.next