19.Remove Nth Node From End of List
来源:互联网 发布:大众软件电子版 pdf 编辑:程序博客网 时间:2024/06/05 15:43
好吧,参考的答案…感觉这种思路棒棒的…and以后要用java…
public class Solution { public ListNode removeNthFromEnd(ListNode head, int n) { if(head==null) return null; //定义两个指针,第一个保持指向最初的head指针 //使head指针移动,先到达访问第n个结点,第二个指针开始出发 //则当head访问完末尾结点时,第二个正好到达从后往前数的第n个结点 ListNode dummy = new ListNode(0); dummy.next = head; ListNode follower = dummy; for(int i=0;i<n;i++){ if(head==null) return null; head = head.next; } while(head!=null){ head = head.next; follower = follower.next; } follower.next = follower.next.next; return dummy.next; }}
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
- Android Service学习之IntentService 深入分析
- logback.xml文件配置
- 指针总结(—)
- 泛型继承的几种写法
- HDU 1335 (16进制以下)把m进制转换为n进制
- 19.Remove Nth Node From End of List
- 洛谷1028
- Scala-02:函数定义、流程控制、异常处理入门实战
- Android四大组件之一——Broadcast Receiver
- Eclipse下如何运行微信SDK_Demo
- RxJS入门(3)----深入Sequence
- 从一个Activity直接跳转到一个Fragment中,进行相应的操作
- 数组首地址与数组名取地址的区别
- 拦截/监听器 —— Filter、Interceptor、Listener