본문 바로가기
개발/알고리즘

[codility] Distinct

by ny0011 2021. 2. 19.
반응형

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

 

Distinct coding task - Learn to Code - Codility

Compute number of distinct values in an array.

app.codility.com

간단하게 중복 제거해주면 된다

python은 set을 사용해도 되고

def solution(A):
    # write your code in Python 3.6
    
    d = {}
    for i in A:
        d[i]=True
    return len(d.keys())
    # return(len(set(A)))

'개발 > 알고리즘' 카테고리의 다른 글

[codility] NumberOfDiscIntersections  (0) 2021.02.19
[codility] MaxProductOfThree  (0) 2021.02.19
[codility] PassingCars  (0) 2021.02.18
[codility] MinAvgTwoSlice  (0) 2021.02.18
[codility] GenomicRangeQuery  (0) 2021.02.18

댓글