Я пробую пробный тест leetCode ..
Given an array nums of n integers, are there elements a, b, c in nums such that a + b + c = 0? Find all unique triplets in the array which gives the sum of zero.
Может кто-нибудь дать совет, где я иду не так ... пометка
Line 8: Char 30: error CS0029: Cannot implicitly convert type 'System.Collections.Generic.List<System.Linq.IGrouping<int, int>>' to 'System.Collections.Generic.List<int>' (in Solution.cs)
Line 12: Char 16: error CS0266: Cannot implicitly convert type 'System.Collections.Generic.List<System.Collections.Generic.List<int>>' to 'System.Collections.Generic.IList<System.Collections.Generic.IList<int>>'. An explicit conversion exists (are you missing a cast?) (in Solution.cs)
public class Solution {
public IList<IList<int>> ThreeSum(int[] nums) {
List<List<int>> myList = new List<List<int>>();
foreach(var i in nums)
{
List<int> triplets = nums.GroupBy(x => x).Where(y => y.Count() >= 3).ToList();
myList.Add(triplets);
}
return myList;
}
}
SO ThreeSum - это интерфейс списка списков.
Итак, я создаю свой возвращаемый объект myList
Итерация по каждому элементу в числах
создание триплета List, получение значений,
и добавив их в myList.
Я знаю, что проблема из-за списка int списков, и я добавляю список к этому.
Так что триплеты должны быть списком int-списков.
Я думаю, тогда вопрос в том, как мне заполнить список списков int одним списком ??