text: # Definition for singly-linked list.
  # class ListNode:
  #     def __init__(self, x):
  #         self.val = x
  #         self.next = None
  
  class Solution:
      # @param A : head node of linked list
      # @param B : head node of linked list
      # @return the head node in the linked list
      def mergeTwoLists(self, A, B):
          head = ListNode('root')
          root = head
          while A is not None and B is not None:
              if A.val <= B.val:
                  root.next = A
                  A = A.next
              else:
                  root.next = B
                  B = B.next
              root = root.next
          
          if A is not None:
              root.next = A
          if B is not None:
              root.next = B
              
          return head.next
                  
                  
                  
  