List из List - как быстро убрать не дубли по условию с использованием linq?

Есть List<MyUrl> lists

    List<MyUrl> lists = new List<MyUrl>
    {
        new MyUrl()
        {
            urls = new List<Uri>() 
            { 
                new Uri("https://1.com"), new Uri("https://2.com"), new Uri("https://3.com"), new Uri("https://4.com") 
            }
        },
        new MyUrl()
        {
            urls = new List<Uri>()
            {
                new Uri("https://7.com"), new Uri("https://2.com"), new Uri("https://3.com"), new Uri("https://4.com")
            }
        },
        new MyUrl()
        {
            urls = new List<Uri>()
            {
                new Uri("https://8.com"), new Uri("https://02.com"), new Uri("https://3.com"), new Uri("https://4.com")
            }
        },
        new MyUrl()
        {
            urls = new List<Uri>()
            {
                new Uri("https://9.com"), new Uri("https://2.com"), new Uri("https://3.com"), new Uri("https://4.com")
            }
        }
    };

В MyUrl содержатся List<Uri> urls

class MyUrl
{
    public List<Uri> urls { get; set; }
}

Как в lists оставить только те MyUrl, которые между собой имеют минимум 3 общих элемента?

То есть в этом примере лишний это

    new MyUrl()
    {
        urls = new List<Uri>()
        {
            new Uri("https://8.com"), new Uri("https://02.com"), new Uri("https://3.com"), new Uri("https://4.com")
        }
    }

Так как у всех остальных имеется единый набор из минимум 3-х элементов:

https://2.com
https://3.com
https://4.com

Дополнение:

Спасибо за предложенное решение, но оно некорректно срабатывает, к примеру, на следующих данных:

            List<MyUrl> lists = new List<MyUrl>
        {
            new MyUrl()
            {
                urls = new List<Uri>() 
                { 
                    new Uri("https://1.com"), new Uri("https://2.com"), new Uri("https://3.com"), new Uri("https://4.com"), new Uri("https://5.com"),
                }
            },
            new MyUrl()
            {
                urls = new List<Uri>()
                {
                    new Uri("https://01.com"), new Uri("https://02.com"), new Uri("https://03.com"), new Uri("https://2.com"),
                    new Uri("https://3.com"), new Uri("https://4.com"), new Uri("https://5.com")
                }
            },
            new MyUrl()
            {
                urls = new List<Uri>()
                {
                    new Uri("https://1.com"), new Uri("https://2.com"), new Uri("https://3.com"), new Uri("https://333.com"), new Uri("https://444.com")
                }
            },
            new MyUrl()
            {
                urls = new List<Uri>()
                {
                    new Uri("https://1.com"), new Uri("https://2.com"), new Uri("https://3.com"), new Uri("https://6666.com"), new Uri("https://7777.com")
                }
            }
        };

Тут лишний:

            new MyUrl()
            {
                urls = new List<Uri>()
                {
                    new Uri("https://01.com"), new Uri("https://02.com"), new Uri("https://03.com"), new Uri("https://2.com"),
                    new Uri("https://3.com"), new Uri("https://4.com"), new Uri("https://5.com")
                }
            }

Так как у всех остальных имеется единый набор из минимум 3-х элементов:

https://1.com
https://2.com
https://3.com

Как можно сделать более корректно?


Ответы (0 шт):