[codility] Counting Elements (python)

728x90
반응형

정렬하면 nlogn이 되고 이 방식은 O(n)으로 풀린다 

 

def solution(A):
    # write your code in Python 3.6
    n=1000001
    check=[False]*n
    for e in A:
        if e>=1:
            check[e-1]=True
    
    for i in range(n):
        if check[i]==False:
            return i+1
            

 

728x90
반응형
TAGS.

Comments