当前位置: 移动技术网 > IT编程>开发语言>C/C++ > Remove Nth Node From End of List(C++)

Remove Nth Node From End of List(C++)

2018年10月05日  | 移动技术网IT编程  | 我要评论

天使不曾离开3,吞噬星空下载txt免费下载,华为荣耀v11

remove nth node from end of list(c++) 。given a linked list, remove then-th node from the end of list and return its head.

/**
* definition for singly-linked list.
* struct listnode {
* int val;
* listnode *next;
* listnode(int x) : val(x), next(null) {}
* };
*/
class solution {
public:
listnode* removenthfromend(listnode* head, int n)
{
if(head->next==null)
return null;
listnode *prev=head,*cur=head;
for(int i=0;i<>
cur=cur->next;
if(cur==null)
return head->next;
while(cur->next!=null)
{
cur=cur->next;
prev=prev->next;
}
prev->next=prev->next->next;
return head;
}
};

如对本文有疑问,请在下面进行留言讨论,广大热心网友会与你互动!! 点击进行留言回复

相关文章:

验证码:
移动技术网