public ListNode removeNthFromEnd(ListNode head, int n) {
        if(n == 0)
            return head;
        int length = 0;
        ListNode node = head;
        while(node != null){
            length++;
            node = node.next;
        }
        if(n == length)
            return head.next;
        int k = length - n -1;
        node = head;
        while(k > 0){
            k--;
            node = node.next;
        }
        node.next = node.next.next;
        return head;
    }