The A set is based on the B set and removes the values that exist in the B set.

        List<int> A = new List<int>() { 1, 1, 2, 3, 3 };
        List<int> B = new List<int>() { 1, 3 };
        AB
        
        List<int> A = new List<int>() {  1, 2, 3};
        
Mar.02,2021

sort first, and then traverse An and B at the same time in order. Pseudo code:

A.sort();
B.sort();
List<int> result = ...;
for (int i = 0, j = 0; i < A.length && j < B.length; iPP) {
    while (A[i] > B[j] && j < B.length) {
        jPP;
    }
    if (j < B.length && A[i] == B[j]) {
        add A[i] to result;
        jPP;
    }
}

https://www.cnblogs.com/wdw31.
PS: be careful not to turn yourself into a joke.

List<int> a = new List<int>() { 1, 1, 2, 3, 3 };
List<int> b = new List<int>() { 1, 3 };
var c = a.Intersect(b).Union(a.Except(b)).ToList();
// 
c.Sort();
// c()
// 
// 
< hr > < hr > < H2 > Supplementary content: < / H2 > < hr >
  1. ignorant people are never reasonable;
  2. Don't blame the subject. After all, you didn't describe whether you want to repeat it or not.
  3. some people, the subject and I are waiting for your apology;
  4. it makes me sick to think that some people need someone to chew and saliva before they are willing to swallow.
List<int> a = new List<int>() { 1, 1, 1, 2, 2, 3, 3, 3 };
List<int> b = new List<int>() { 1, 3 };
a.Sort();
b.Sort();
// 
List<int> c = a.Intersect(b).Distinct().Union(a.Except(b)).ToList();
List<int> d = a.Select(i => i).ToList();
// 
b.ForEach(item => d.RemoveAt(d.FindIndex(aItem => aItem == item)));
c.Sort();
d.Sort();
Console.WriteLine("a=" + string.Join(",", a));
Console.WriteLine("b=" + string.Join(",", b));
Console.WriteLine("c=" + string.Join(",", c));
Console.WriteLine("d=" + string.Join(",", d));
Menu