#NEWLINE# def removeNthFromEnd( self , head , n ) : #NEWLINE# #INDENT# '\n        O(n)+O(n)\n        :param head: head node\n        :param n: the nth node from the end\n        :return: ListNode, head node\n        ' #NEWLINE# dummy = ListNode ( 0 ) #NEWLINE# dummy . next = head #NEWLINE# length = 0 #NEWLINE# pre = dummy #NEWLINE# while pre . next : #NEWLINE# #INDENT# length += 1 #NEWLINE# pre = pre . next #NEWLINE# #UNINDENT# pre = dummy #NEWLINE# count = 0 #NEWLINE# while dummy . next : #NEWLINE# #INDENT# cur = pre . next #NEWLINE# if ( count == ( length - n ) ) : #NEWLINE# #INDENT# pre . next = cur . next #NEWLINE# break #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# count += 1 #NEWLINE# pre = pre . next #NEWLINE# #UNINDENT# #UNINDENT# return dummy . next