[codility] max counters (python)
728x90
반응형
계속해서 현재의 최대값이 있다면 기록해둔다.
만약 n+1이 나오면 가장 큰 값을 바꿔주고 그것보다 작은 수는 업데이트해준다
최소한의 값이 되지 않은 수들을 다시 가장 큰 값 변수에 기록된 걸로 바꿔준다
# you can write to stdout for debugging purposes, e.g.
# print("this is a debug message")
def solution(N, A):
res=[0]*N
biggest,cur=0,0
for e in A:
if e==N+1:
biggest=cur
else:
if biggest>res[e-1]:
res[e-1]=biggest
res[e-1]+=1
if res[e-1]>cur:
cur=res[e-1]
for i in range(N):
if res[i]<biggest:
res[i]=biggest
return res
728x90
반응형
'codility' 카테고리의 다른 글
[codility] Distinct (python) (0) | 2020.10.14 |
---|---|
[codility] Counting Elements (python) (0) | 2020.10.14 |
[codility] TapeEquilibrium (python) (0) | 2020.10.14 |
[codility] Solution to Binary-Gap by codility (python) (0) | 2020.10.14 |
[codility] perm missing elem (python) (0) | 2020.10.14 |
TAGS.