<jupyter_start><jupyter_text>合并两个有序链表将两个有序链表合并为一个新的有序链表并返回。新链表是通过拼接给定的两个链表的所有节点组成的。 示例：* 输入：1->2->4, 1->3->4* 输出：1->1->2->3->4->4 方法一<jupyter_code># Definition for singly-linked list.
# class ListNode(object):
#     def __init__(self, x):
#         self.val = x
#         self.next = None

class Solution(object):
    def mergeTwoLists(self, l1, l2):
        """
        :type l1: ListNode
        :type l2: ListNode
        :rtype: ListNode
        """
        head = ListNode(0)
        tprev = head
        while l1 is not None and l2 is not None:
            if l1.val <= l2.val:
                tprev.next = l1
                l1 = l1.next
            else:
                tprev.next = l2
                l2 = l2.next
            tprev = tprev.next
        if l1 is None:
            tprev.next = l2
        if l2 is None:
            tprev.next = l1
        return head.next<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.1119648737650933, 'fraction_numerical': 0.03402854006586169, 'mean_word_length': 1.5835694050991502, 'pattern_counts': {'":': 0, '<': 6, '<?xml version=': 0, '>': 14, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '1', 'dir': 'jupyter-structured-clean-dedup', 'id': '358865', 'license': 'BSD-3-Clause', 'n_tokens_mistral': 365, 'n_tokens_neox': 375, 'n_words': 75, 'path': 'leetcode/021-merge-two-sorted-lists.ipynb', 'repo_name': 'sdyz5210/python', 'size': '911'}