Algorithm/codility

Lesson6. Sorting - Distinct

nuKeguyS 2018. 7. 24. 14:20

Distinct - Compute number of distinct values in an array.

https://app.codility.com/programmers/lessons/6-sorting/distinct/

문제요약

N개의 정수 배열 A가 주어지면, A의 유일한 값의 갯수를 반환(중복을 제거한)

Complexity:

expected worst-case time complexity is O(N*log(N));

expected worst-case space complexity is O(N) (not counting the storage required for input arguments).

풀이

정렬 후에 이전값과 다른 값의 갯수만 센다.