/**
* Definition for singly-linked list.
* type ListNode struct {
* Val int
* Next *ListNode
* }
*/funcmergeTwoLists(list1*ListNode,list2*ListNode)*ListNode{dummyNode:=&ListNode{}head:=dummyNodeforlist1!=nil&&list2!=nil{iflist1.Val<list2.Val{head.Next=list1list1=list1.Next}else{head.Next=list2list2=list2.Next}head=head.Next}iflist1!=nil{head.Next=list1}else{head.Next=list2}returndummyNode.Next}
/**
* Definition for singly-linked list.
* type ListNode struct {
* Val int
* Next *ListNode
* }
*/funcmergeTwoLists(list1*ListNode,list2*ListNode)*ListNode{iflist1==nil{returnlist2}elseiflist2==nil{returnlist1}elseiflist1.Val<list2.Val{list1.Next=mergeTwoLists(list1.Next,list2)returnlist1}else{list2.Next=mergeTwoLists(list1,list2.Next)returnlist2}returnnil}