leetcode 19. Remove Nth Node From End of List

来源:互联网 发布:出国旅游软件 编辑:程序博客网 时间:2024/05/17 04:29
class Solution{public:ListNode* removeNthFromEnd(ListNode* head, int n){ListNode * p1, **p2;p1 = head;p2 = &head;for (int i = 1; i < n; ++i){p1 = p1->next;}while (p1->next != NULL){p1 = p1->next;p2 = &((*p2)->next);}*p2 = (*p2)->next;return head;}};

0 0
原创粉丝点击