原题地址

 

基本模拟,记得最后把尾节点next置为NULL...

 

代码:

 1 ListNode *deleteDuplicates(ListNode *head) {
 2         ListNode *h = NULL;
 3         ListNode *t = NULL;
 4         
 5         while (head) {
 6             if (!h)
 7                 h = t = head;
 8             else if (head->val != t->val) {
 9                 t->next = head;
10                 t = t->next;
11             }
12             head = head->next;
13         }
14         if (t)
15             t->next = NULL;
16         
17         return h;
18 }

 

相关文章:

  • 2021-09-20
  • 2021-06-18
  • 2021-08-21
  • 2021-11-15
  • 2022-12-23
  • 2021-10-16
猜你喜欢
  • 2021-06-29
  • 2022-01-19
  • 2021-06-02
  • 2022-01-05
  • 2021-05-17
  • 2021-05-31
  • 2021-05-27
相关资源
相似解决方案