/** * struct ListNode { * int val; * struct ListNode *next; * }; */ /** * 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可 * * * @param head ListNode类 * @param n int整型 * @return ListNode类 */ struct ListNode* removeNthFromEnd(struct ListNode* head, int n ) { // write code hereif(head==NULL) int length=0; struct ListNode * dummy=(struct ListNode *)malloc(sizeof(struct ListNode)); dummy->next=head; struct ListNode * p=head; while(p) { p=p->next; length++; } p=dummy; for(int i=0;i<length-n;i++) { p=p->next; } p->next=p->next->next; return dummy->next; }