/**
* Definition for singly-linked list.
* struct ListNode {
* int val;
* struct ListNode *next;
* };
*/
struct ListNode {
int val;
struct ListNode *next;
};
#define INT_MIN -2147483648
struct ListNode* mergeTwoLists(struct ListNode* l1, struct ListNode* l2)
{
struct ListNode *head=(struct ListNode*)malloc(sizeof(struct ListNode));
head->val=INT_MIN;
head->next=NULL;
struct ListNode* p=head;
while(l1 && l2)
{
if(l1->val > l2->val)
{
p->next=l2;
l2=l2->next;
}else{
p->next=l1;
l1=l1->next;
}
p=p->next;
}
p->next = l1 ? l1 : l2;
return head->next;
}
merge two list
最新推荐文章于 2024-01-12 14:30:52 发布