其他分享
首页 > 其他分享> > 面试题 02.01. 移除重复节点

面试题 02.01. 移除重复节点

作者:互联网

 1 /**
 2  * Definition for singly-linked list.
 3  * struct ListNode {
 4  *     int val;
 5  *     struct ListNode *next;
 6  * };
 7  */
 8 
 9 
10 struct ListNode* removeDuplicateNodes(struct ListNode* head){
11     int sum[30000];
12     for(int i=0;i<30000;i++)
13     {
14         sum[i]=0;
15     }
16     struct ListNode* p =(struct ListNode *)malloc(sizeof(struct ListNode)),*tail;
17     p->next = NULL;
18     tail = p;
19 
20     while(head)
21     {
22         sum[head->val]++;
23         if(sum[head->val]==1)
24         {
25              struct ListNode* s =(struct ListNode *)malloc(sizeof(struct ListNode));
26              s->val = head->val;
27              s->next = NULL;
28              tail->next = s;
29              tail = s;
30         }
31 
32         head = head->next;
33     }
34 
35     return p->next;
36 }

 

标签:面试题,ListNode,struct,val,int,02.01,head,next,移除
来源: https://www.cnblogs.com/Knightl8/p/14889897.html