Remove Nth Node from End of List
2013-05-15 04:14
363 查看
/** * 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 == null) return null; int i = 0; ListNode tail = head; ListNode node = head; while(i++ < n){ tail = tail.next; } if(tail == null) return head.next; while(tail.next != null){ tail = tail.next; node = node.next; } node.next = node.next.next; return head; } }
相关文章推荐
- 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
- 19. Remove Nth Node From End of List
- LeetCode 19 Remove Nth Node From End of List
- 19. Remove Nth Node From End of List
- remove the nth node from the end of the list
- LeetCode - Remove Nth Node From End of List
- LeetCode: Remove Nth Node From End of List
- 19. Remove Nth Node From End of List
- 【LeetCode】Remove Nth Node From End of List && 【九度】题目1517:链表中倒数第k个结点
- [Leetcode] Remove Nth Node From End of List
- 19. Remove Nth Node From End of List
- Remove Nth Node From End of List_Leetcode_#19