public static ListNode removeNthFromEnd(ListNode head, int n) {
		ListNode nhead = head;
		ListNode pre = null;
		ListNode node = nhead;
		while (node != null) {
			int k = n;
			ListNode p = node;
			while (k > 0 && p != null) {
				p = p.next;
				k -= 1;
			}

			if (p == null) {
				// node is the nth node from end;
				if (pre == null) {
					// it is the first node to delete;
					nhead = node.next;
				} else {
					pre.next = node.next;
				}

				break;
			} else {
				pre = node;
				node = node.next;
			}
		}

		return nhead;
	}