Find all duplicates in an array using c#


  • 0
    E
    public static IList<int> FindDuplicates(int[] nums)
            {
                var result = new List<int>();
                var groups = nums.GroupBy(v => v);
                foreach (var group in groups)
                {
                    if (group.Count() == 2) \\ or count > 1  
                        result.Add(group.Key);
                }
                    return result;
            }
    

Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.