Remove Nth Node From End of List
2013-04-18 16:24
309 查看
/** * 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) { // Start typing your Java solution below // DO NOT write main() function if(head.next==null)return null; ListNode last = head; for(int i = 0; i<n;i++){ last = last.next; } if(last==null)return head.next; ListNode now = head; while(last.next!=null){ last = last.next; now = now.next; } now.next = now.next.next; return head; } }
相关文章推荐
- [leetcode] 19. Remove Nth Node From End of List 解题报告
- LeetCode 19. Remove Nth Node From End of List(链表)
- [LeetCode] 19. Remove Nth Node From End of List
- Remove Nth Node From End of List
- LeetCode题解——Remove Nth Node From End of List
- LeetCode(46)-Remove Nth Node From End of List
- 19. Remove Nth Node From End of List(python)
- Remove Nth Node From End of List
- [C语言][LeetCode][19]Remove Nth Node From End of List
- 【Leetcode】之Remove Nth Node From End of List
- 19. Remove Nth Node From End of List(移除链表的倒数第n个节点)
- LeetCode 19. Remove Nth Node From End of List
- LeetCode 17.Letter Combinations of a Phone Number & 19.Remove Nth Node From End of List
- Remove Nth Node From End of List---leetcode 我的java题解
- LeetCode:Remove Nth Node From End of List
- 【Leetcode】【python】Remove Nth Node From End of List
- leetcode 19. 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--19. Remove Nth Node From End of List