一、

1. Remove Duplicates from Sorted List II

 1 class Solution {
 2 public:
 3     ListNode* deleteDuplicates(ListNode* head) {
 4         ListNode* dummy = new ListNode(0);
 5         dummy->next = head;
 6         ListNode* pre = dummy;
 7         ListNode* cur = head;
 8         while (cur != NULL && cur->next != NULL) {
 9             if (cur->val == cur->next->val) {
10                 while(cur->next != NULL && cur->val == cur->next->val) {
11                     cur = cur->next;            
12                 }
13                 pre->next = cur->next;
14                 cur = cur->next;
15             } else {
16                 pre = pre->next;
17                 cur = cur->next;
18             }
19         }
20         return dummy->next;
21     }
22 };
View Code

相关文章:

  • 2022-01-31
  • 2021-08-08
  • 2021-11-14
  • 2021-10-16
  • 2021-10-23
  • 2021-11-13
  • 2021-06-09
  • 2021-07-16
猜你喜欢
  • 2021-09-27
  • 2021-05-27
  • 2021-12-28
  • 2021-07-12
  • 2021-07-26
  • 2021-08-02
  • 2021-06-07
相关资源
相似解决方案