Java/Remove Nth Node From End of List.java
public class Solution {

    /**
     * Time:   O(n)
     * Memory: O(1)
     */
    public ListNode removeNthFromEnd(ListNode head, int n) {
        ListNode fast = head, slow = head;

        for (int k = 0; k < n; ++k)
            fast = fast.next;

        if (fast == null)
            return head.next;

        while (fast.next != null) {
            fast = fast.next;
            slow = slow.next;
        }

        slow.next = slow.next.next;

        return head;
    }
}
