-
Lesson6. Sorting - DistinctAlgorithm/codility 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).
풀이
정렬 후에 이전값과 다른 값의 갯수만 센다.This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersdef solution(A): A.sort() size = len(A) count = size for i in range(1, size): if A[i] == A[i-1]: count -= 1 return count