public static ListNode removeNthFromEnd(ListNode head, int n) {
        ListNode p = head;
        ListNode q = null;
        int num = 0;
        while (null != p) {
        	p = p.next;
        	num = num + 1;
        }
        if (n > num) return head;
        if (n == num) return head.next;
        p = head; q = head;
        int step = 0;
        while (null != p) {
        	q = p;
        	p = p.next;
        	step = step + 1;
        	if (step == num - n) {
        		break;
        	}
        }
        if (null == p) {q.next = null;}
        else {q.next = p.next;}
        return head;
    }