思春期狂想曲,b型h系全集,t-ara 小苹果
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.
/**
* definition for singly-linked list.
* struct listnode {
* int val;
* listnode *next;
* listnode(int x) : val(x), next(null) {}
* };
*/
class solution {
public:
listnode* mergetwolists(listnode* l1, listnode* l2)
{
if(l1==null)
return l2;
if(l2==null)
return l1;
listnode* result=new listnode(0);
listnode* cur=result;
while(l1!=null&&l2!=null)
{
if(l1->val
{
cur->next=l1;
l1=l1->next;
}
else
{
cur->next=l2;
l2=l2->next;
}
cur=cur->next;
}
while(l1==null&&l2!=null)
{
cur->next=l2;
l2=l2->next;
cur=cur->next;
}
while(l2==null&&l1!=null)
{
cur->next=l1;
l1=l1->next;
cur=cur->next;
}
return result->next;
}
};
如对本文有疑问,请在下面进行留言讨论,广大热心网友会与你互动!! 点击进行留言回复
如何在没有core文件的情况下用dmesg+addr2line定位段错误
用QT制作3D点云显示器——QtDataVisualization
网友评论