[TIL] 109 중복 요소 제거 Distinct(), HashSet

업데이트:

카테고리:

태그: ,


Distinct()



코테

   알고리즘 연습하기
   클린코드 정리하기
   [ ] 디자인 코드 패턴 이해,정리하기. 책사기
   [ ] 자료구조 디자인패턴 강의 다시 듣기.







Distinct(), hashSet

// 10개 입렵받은 후 서로 다른 나머지의 개수를 출력

int[] a = new int[10];

for (int i = 0; i < 10; i++)
{
    string input = Console.ReadLine();
    a[i] = int.Parse(input)%42;
}

// Distinct()
int[] b = a.Distinct().ToArray();

Console.WriteLine(b.Length);

// HashSet<>()

HashSet<int> set = new HashSet<int>(a);
int[] result = set.ToArray();

Console.WriteLine(set.Count);

  • Distinct() : 배열에 중복요소를 제거합니다.
  • HashSet : 중복을 허용하지 않는 자료구조







잡담, 일기?

이력서 정리, 자소서 작성, 면접준비중, 코테




📔

댓글남기기