Merge two sorted linked lists and return it as a new list.
The new list should be made by splicing together the nodes of the first two lists.
func mergeTwoLists(l1 *ListNode, l2 *ListNode) *ListNode {
if l1==nil{
return l2
}
if l2==nil{
return l1
}
p1:=l1
p2:=l2
var head * ListNode
var p *ListNode
for p1!=nil&&p2!=nil{
if p1.Val<p2.Val{
if head==nil{
head=p1
p=p1
p1=p1.Next
}else {
p.Next=p1
p=p1
p1=p1.Next
}
}else {
if head==nil{
head=p2
p=p2
p2=p2.Next
}else {
p.Next=p2
p=p2
p2=p2.Next
}
}
}
if p1!=nil{
p.Next=p1
}
if p2!=nil{
p.Next=p2
}
return head
}