class Solution {
public:
    ListNode* removeNthFromEnd(ListNode* head, int n) {
        if (!head->next) return NULL;
        ListNode *pre = head, *cur = head;
        for (int i = 0; i < n; ++i) cur = cur->next;
        if (!cur) return head->next;
        while (cur->next) {
            cur = cur->next;
            pre = pre->next;
        }
        pre->next = pre->next->next;
        return head;
    }
};

相关文章:

  • 2021-07-16
  • 2021-08-18
  • 2021-10-31
  • 2021-07-13
  • 2021-10-13
  • 2021-10-25
  • 2021-05-16
猜你喜欢
  • 2021-05-31
  • 2021-12-09
  • 2021-11-23
相关资源
相似解决方案