Generation

generate functionFri, 20 Jan 2023

Сгенерировать два массива и переписать в третий массив общие элементы первых двух массивов без повторений

List<int> Intersection(List<int> first, List<int> second) { var result = new List<int>(); foreach(var item in first) { if (first.IndexOf(item) == second.IndexOf(item)) { result.Add(item); } } return result; } List<int> first = new List<int>() { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10}; List<int> second = new List<int>() { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10}; Intersection(first, second);

Questions about programming?Chat with your personal AI assistant