19、Remove Nth Node From End of List
来源:互联网 发布:linux ping 100个包 编辑:程序博客网 时间:2024/04/29 16:58
Given a linked list, remove the nth node from the end of list and return its head.
For example,
Given a linked list, remove the nth node from the end of list and return its head.
For example,
Note:Given n will always be valid.
Try to do this in one pass.
Linked List Two Pointers
ListNode *removeNthFromEnd(ListNode *head, int n) { //此题要求比遍历一遍搞定,需要一个指针来指向删除节点的前面节点,对于删除头结点的情况需要特殊考虑, p -> next和q-> next节点的关系需要搞清楚 ListNode *p = head, *q = head; while (n--) q = q -> next; if (q == NULL) return p -> next; while (q -> next) { p = p -> next; q = q -> next; } p -> next = p -> next -> next; return head; }
0 0
- Remove Nth Node From End of List
- Remove Nth Node From End of List
- Remove Nth Node From End of List
- Remove Nth Node From End of List
- Remove Nth Node from End of List
- Remove Nth Node From End of List
- Remove Nth Node From End of List
- Remove Nth Node From End of List
- Remove Nth Node From End of List
- Remove Nth Node From End of List
- Remove Nth Node From End of List
- Remove Nth Node From End of List
- Remove Nth Node From End of List
- Remove Nth Node From End of List
- Remove Nth Node From End of List
- Remove Nth Node From End of List
- Remove Nth Node From End of List
- Remove Nth Node From End of List
- 广搜
- SQL VIEW(视图)
- adb shell input text 输入特殊字符 &
- nodejs连接mysql
- Android 常用 mimeType 表
- 19、Remove Nth Node From End of List
- Activity切换动画效果
- ios push推送
- 18 commands to monitor network bandwidth on Linux server
- 79使用相机拍照
- WebSerice学习笔记1——WebSerice基础
- hdu---1061 Rightmost Digit
- opencv 图像降噪函数
- Android 屏幕录屏,然后转为GIF图