본문 바로가기
Problem Solving/Codility

[Python] 4.3. MissingInteger

by 부르르 2021. 3. 15.

https://app.codility.com/programmers/lessons/4-counting_elements/

 

4. Counting Elements lesson - Learn to Code - Codility

Calculate the values of counters after applying all alternating operations: increase counter by 1; set value of all counters to current maximum.

app.codility.com


정답률: 100% (Task Score 100%, Correctness 100%, Performance 100%)

시간복잡도: O(N) or O(N * log(N))

def solution(A):

    _A = set(sorted(A))

    answer = 1

    for i in _A:
        if i > 0 and i <= answer:
            answer += 1
        else:
            continue

    return answer
728x90
반응형

'Problem Solving > Codility' 카테고리의 다른 글

[Python] 5.1. CountDiv  (0) 2021.03.15
[Python] 4.4. PermCheck  (0) 2021.03.15
[Python] 4.2. MaxCounters  (0) 2021.03.14
[Python] 4.1. FrogRiverOne  (0) 2021.03.13
[Python] 3.3. TapeEquilibrium  (0) 2021.03.11

댓글