GeezerVisonThe World Wide Web, restored to 800 pixels of glory. |
| Home|About|Gaming cabinet|Archives|How it works|Starter sites |
GeezerVison is showing github.com — LeetCode/L019_Remove_Nth_Node_From_End_of_List.java at master · likevson/LeetCode Expand file tree/ Copy pathL019_Remove_Nth_Node_From_End_of_List.javaMore file actions 40 lines (29 loc) · 600 Bytes / Copy pathL019_Remove_Nth_Node_From_End_of_List.javaFile metadata and controls40 lines (29 loc) · 600 Bytes 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 package LeetCode; public class L019_Remove_Nth_Node_From_End_of_List { public static class ListNode { int val; ListNode next; ListNode(int x) { val = x; } } public ListNode removeNthFromEnd(ListNode head, int n) { if (head == null || head.next == null) { return null; } ListNode first = head; ListNode second = head; for (int i = 0; i < n; i++) { first = first.next; if (first == null) { return head.next; } } while (first.next != null) { first = first.next; second = second.next; } second.next = second.next.next; return head; } } |
| You are visitor 01402792 — GeezerVison does not store the pages you look up. Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required. |