private List<int> FindDuplicates(List<int> numbers)
    {
        // 숫자의 등장 횟수를 저장할 딕셔너리 생성
        Dictionary<int, int> counts = new Dictionary<int, int>();

        // 리스트를 순회하면서 각 숫자의 등장 횟수를 셈
        foreach (int number in numbers)
        {
            if (counts.ContainsKey(number))
            {
                counts[number]++;
            }
            else
            {
                counts.Add(number, 1);
            }
        }

        // 등장 횟수가 2 미만인 숫자만을 새 리스트에 추가
        List<int> duplicates = counts.Where(pair => pair.Value < 2).Select(pair => pair.Key).ToList();

        return duplicates;
    }

+ Recent posts