Merge Two Sorted Lists
# Definition for singly-linked list.
# class ListNode:
# def __init__(self, x):
# self.val = x
# self.next = None
class Solution:
# @param {ListNode} l1
# @param {ListNode} l2
# @return {ListNode}
def mergeTwoLists(self, l1, l2):
start = ListNode(0)
curNode = start
while l1 is not None and l2 is not None:
if l1.val < l2.val:
curNode.next = l1
l1 = l1.next
else:
curNode.next = l2
l2 = l2.next
curNode = curNode.next
if l1 is not None:
curNode.next = l1
if l2 is not None:
curNode.next = l2
return start.next