public static ListNode removeNthFromEnd(ListNode head, int n) {
        ListNode slow = head;
        ListNode fast = head;
        int x = n;
        while (x >= 0 && fast != null) {
            fast = fast.next;
            x--;
        }
        if (fast == null && x > 0) {
            return head;
        }
        if (fast == null && x == 0) {
            return null;
        } 
        while (fast != null) {
            slow = slow.next;
            fast = fast.next;
        }
        slow.next = slow.next.next;
        return head;
    }