leetcode 19:删除链表的倒数第N个节点

xiaoxiao2022-06-11  34

ListNode* removeNthFromEnd(ListNode* head, int n) { ListNode*l1=head; int c=0; while(l1!=NULL) { c+=1; l1=l1->next; } if(c==n)return head->next; if(c<n)return NULL; ListNode*l2=head; for(int i=1;i<c-n;i++){ l2=l2->next; } ListNode *l3=l2->next; l2->next=l3->next; return head; }

 

转载请注明原文地址: https://www.6miu.com/read-4931930.html

最新回复(0)