原题地址

 

基本模拟

 

代码:

 1 ListNode *removeNthFromEnd(ListNode *head, int n) {
 2         ListNode *fast = head;
 3         ListNode *slow = head;
 4         ListNode *prev = NULL;
 5         
 6         while (--n)
 7             fast = fast->next;
 8         while (fast->next) {
 9             fast = fast->next;
10             prev = slow;
11             slow = slow->next;
12         }
13         if (!prev)
14             return head->next;
15         prev->next = slow->next;
16         return head;
17 }

 

相关文章:

  • 2021-07-16
  • 2021-05-16
  • 2021-07-16
  • 2021-08-24
  • 2021-09-10
猜你喜欢
  • 2021-10-13
  • 2021-09-02
  • 2022-01-03
  • 2021-08-18
  • 2021-10-31
  • 2021-11-23
  • 2021-07-13
相关资源
相似解决方案