<jupyter_start><jupyter_text>Given two sorted integer arrays nums1 and nums2, merge nums2 into nums1 as one sorted array.Note:The number of elements initialized in nums1 and nums2 are m and n respectively.You may assume that nums1 has enough space (size that is greater or equal to m + n) to hold additional elements from nums2.Example:Input:nums1 = [1,2,3,0,0,0], m = 3nums2 = [2,5,6],       n = 3Output: [1,2,2,3,5,6]<jupyter_code>class Solution:
    def merge(self, nums1, m, nums2, n):
        """
        :type nums1: List[int]
        :type m: int
        :type nums2: List[int]
        :type n: int
        :rtype: void Do not return anything, modify nums1 in-place instead.
        """

        while m > 0 and n > 0:
            if nums1[m-1] >= nums2[n-1]:
                nums1[m+n-1] = nums1[m-1]
                m -= 1
            else:
                nums1[m+n-1] = nums2[n-1]
                n -= 1
        if n > 0:
            nums1[:n] = nums2[:n]<jupyter_output><empty_output><jupyter_text>Linkedlist<jupyter_code># Definition for singly-linked list.
# class ListNode(object):
#     def __init__(self, x):
#         self.val = x
#         self.next = None

class Solution(object):
    def mergeKLists(self, lists):
        """
        :type lists: List[ListNode]
        :rtype: ListNode
        """
        def mergeList(l1, l2):
            cur = dummy = ListNode(0)
            while l1 and l2 :
                if l1.val < l2.val:
                    cur.next = l1
                    l1 = l1.next
                else :
                    cur.next = l2
                    l2 = l2.next
                cur = cur.next     
            if(l1):
                cur.next = l1
            if(l2):
                cur.next = l2
            return dummy.next  
        
        if not lists:
            return None
        left, right = 0, len(lists) - 1
        while right > 0 :
            if left >= right:
                left = 0
            else:
                lists[left] = mergeList(lists[left], lists[right])
                left += 1
                right -= 1
        return lists[0]<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.10619469026548672, 'fraction_numerical': 0.03493246390312063, 'mean_word_length': 1.4326160815402038, 'pattern_counts': {'":': 0, '<': 10, '<?xml version=': 0, '>': 15, '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': '2', 'dir': 'jupyter-structured-clean-dedup', 'id': '397235', 'license': 'MIT', 'n_tokens_mistral': 722, 'n_tokens_neox': 688, 'n_words': 193, 'path': 'Python/Merge.ipynb', 'repo_name': 'AlphaTwist/Code-squad', 'size': '2147'}