반응형
시간 복잡도: O(N**2) --> 54%의 정답률
# you can write to stdout for debugging purposes, e.g.
# print("this is a debug message")
def solution(X, A):
# write your code in Python 3.6
# step 1 - input x,a
# already succeed
# step 2 - if 1,2,3,.. in arr then, change the index into 0
# else: continue
arr = list(range(1,X+1))
for i in range(len(A)):
if A[i] in arr:
arr[A[i]-1] = 0
if sum(arr) == 0:
return i
pass
시간 복잡도: O(N) --> 100%의 정답률
# you can write to stdout for debugging purposes, e.g.
# print("this is a debug message")
def solution(X, A):
# write your code in Python 3.6
# step 1 - input x,a
# already succeed
# step 2 - # step 2 - if 1,2,3,.. in arr then, change the index into 0
# else: continue
check = [0] * X
check_sum = 0
for i in range(len(A)):
if check[A[i]-1] == 0:
check[A[i]-1] = 1
check_sum += 1
if check_sum == X:
return i
return -1
pass
반응형
'Codility' 카테고리의 다른 글
Codility - MissingInteger (0) | 2020.04.17 |
---|---|
Codility - MaxCounters (0) | 2020.04.15 |
Codility - TapeEquilibrium (0) | 2020.04.13 |
Codility - PermMissingElem (0) | 2020.04.12 |
Codility - FrogJmp (0) | 2020.04.11 |