leetcode Remove Nth Node From End of List
来源:互联网 发布:安卓运行ubuntu 编辑:程序博客网 时间:2024/05/18 05:34
双指针大法又显神通。
/** * Definition for singly-linked list. * public class ListNode { * int val; * ListNode next; * ListNode(int x) { * val = x; * next = null; * } * } */public class Solution { public ListNode removeNthFromEnd(ListNode head, int n) { if(head==null)return null; ListNode ret=new ListNode(-1); ret.next=head; ListNode p1=ret; ListNode p2=ret; int i=0; while(i<n&&p2.next!=null){ p2=p2.next; i++; } if(p2==null&&i!=n)return head; while(p2.next!=null){ p1=p1.next; p2=p2.next; } p1.next=p1.next.next; return ret.next; }}
0 0
- LeetCode[Linked List]: Remove Nth Node From End of List
- 19. Remove Nth Node From End of List leetcode list
- [Leetcode]LeetCode 19:Remove Nth Node From End of List
- LeetCode: Remove Nth Node From End of List
- LeetCode: Remove Nth Node From End of List
- [Leetcode] Remove Nth Node From End of List
- LeetCode: Remove Nth Node From End of List
- leetcode 40: Remove Nth Node From End of List
- [LeetCode] Remove Nth Node From End of List
- Leetcode 19 Remove Nth Node From End of List
- [Leetcode] Remove Nth Node From End of List
- [LeetCode]Remove Nth Node From End of List
- LeetCode-Remove Nth Node From End of List
- [LeetCode] Remove Nth Node From End of List
- LeetCode 19: Remove Nth Node From End of List
- LeetCode - Remove Nth Node From End of List
- LeetCode | Remove Nth Node From End of List
- leetcode之Remove Nth Node From End of List
- PowerBuilder基础知识
- ARC 下两种释放对象的方法
- UPnP基本原理以及在NAT中的应用
- Android 给指定RelativeLayout添加雪花下落效果
- listview dividerheight
- leetcode Remove Nth Node From End of List
- MySQL数据库备份命令
- Java系列笔记(3) - Java 内存区域和GC机制
- Android4.2锁屏流程【Android锁屏解析三】
- Android实现元素间的分割线 android:divider=""(3.0以上特性)支持3.0以下
- 转jstl的一些用法
- IAR修改工程名称的方法
- 黑马程序员--08 OC 核心语法
- 欢迎使用CSDN-markdown编辑器1