본문 바로가기
Problem Solving/Codility

[Python] 4.4. PermCheck

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


Task Score 100%

Correctness 100%

Performance 100%

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

def solution(A):

    _A = sorted(A)
    _B = range(1,len(A)+1)

    answer = 1

    for i in range(len(A)):
        if _B[i] == _A[i]:
            pass
        else:
            answer = 0
            return answer

    return answer
728x90
반응형

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

[Python] 5.2. GenomicRangeQuery  (0) 2021.03.16
[Python] 5.1. CountDiv  (0) 2021.03.15
[Python] 4.3. MissingInteger  (0) 2021.03.15
[Python] 4.2. MaxCounters  (0) 2021.03.14
[Python] 4.1. FrogRiverOne  (0) 2021.03.13

댓글