package main
import . "nc_tools"

func Merge( pHead1 *ListNode ,  pHead2 *ListNode ) *ListNode {
    // write code here
    dummy := &ListNode{}
    prev := dummy

    for pHead1 != nil && pHead2 != nil {
        if pHead1.Val < pHead2.Val {
            prev.Next = pHead1
            pHead1 = pHead1.Next
        } else {
            prev.Next = pHead2
            pHead2 = pHead2.Next
        }
        prev = prev.Next
    }
    if pHead1 == nil {
        prev.Next = pHead2
    }
    if pHead2 == nil {
        prev.Next = pHead1
    }
    return dummy.Next
}