Home > Back-end >  For C language list delete duplicate nodes
For C language list delete duplicate nodes

Time:12-09

title
Example 1:
Input: [1, 2, 3, 3, 2, 1]
Output: [1, 2, 3]
Example 2:
Input: [1, 1, 1, 1, 2]
Output: [1, 2]
Tip:
Chain length of the table within the scope of the [0, 20000],
List elements within the scope of the [0, 20000],
Source: the power button (LeetCode)
Link: https://leetcode-cn.com/problems/remove-duplicate-node-lcci
Copyright belongs to the collar of the network, commercial reproduced please contact the official authorization, non-commercial reprint please indicate the source,


My code
#include
Struct number
{
Int num.
Struct number * next;
};
//testing whether has the number in the array
Int visit (int * p, int n, int I)
{
for(; I> 0; I -, p++)
If (* p==n) return 1;
return 0;
}

Int main ()
{
Struct head number * and * (p1, * (p2);
Int a [20001], I=0, * p;
P1=p2;
The head=p1;
While (the scanf (" % d ", & amp; A [I])!=(EOF)
{
P1 - & gt; Num=a, [I].
P=a;
If (visit (p, a [I], I))
{
The p2 - & gt; Next=p1 - & gt; Next;
}
The else
{
P1 p2=;
P1=p1 - & gt; Next;
}
i++;
}
While (I -)
{
Printf (" % d ", the head - & gt; Num);
The head=head - & gt; Next;
}
return 0;

}

CodePudding user response:

Directly detected in an array or a list with the corresponding value, do nothing, just skip the current value

CodePudding user response:

No malloc memory?

CodePudding user response:

Singly linked list data structure on data sort http://bbs.csdn.net/topics/392201633

CodePudding user response:

refer to the second floor MianHou response:
no malloc memory?

For who open memory

CodePudding user response:

reference 4 floor qq_46070792 response:
Quote: refer to the second floor MianHou response:
no malloc memory?

For who open memory



The main function of creating list when you have no open memory p1 p2 head you directly to the assignment problem
  • Related