https://app.codility.com/demo/results/training5MBAYJ-A83/
Test results - Codility
A non-empty array A consisting of N integers is given. The unique number is the number that occurs exactly once in array A. For example, the following array A: A[0] = 4 A[1] = 10 A[2] = 5 A[3] = 4 A[4] = 2 A[5] = 10 contains two unique numbers (5 and 2). Y
app.codility.com
Point
- 딕셔너리를 만들어 입력값에 대해 카운트를 한다
- 딕셔너리 for loop를 통해 unique한 값에 대해서 비교하여 return 한다
Tip
- 내장 라이브러리 중 defaultdict 사용
Task Score
100%
Correctness
100%
Performance
100%
Detected time complexity
O(N * log(N))
from collections import defaultdict
def solution(A):
dic = defaultdict(int)
for a in A:
dic[a] += 1
for k,v in dic.items():
if v == 1:
return k
return -1
문제를 푸는데 도움이 된 테스트 케이스
728x90
반응형
'Problem Solving > Codility' 카테고리의 다른 글
[Python] TreeHeight (0) | 2021.07.18 |
---|---|
[Python] StrSymmetryPoint (0) | 2021.07.18 |
[Python] DisappearingPairs (0) | 2021.07.15 |
[Python] 8.1. Dominator (0) | 2021.04.05 |
[Python] 7.3. Nesting (0) | 2021.03.30 |
댓글