본문 바로가기
Problem Solving/Codility

[Python] 2.2. OddOccurrencesInArray

by 부르르 2021. 3. 7.

https://app.codility.com/programmers/lessons/2-arrays/

 

2. Arrays lesson - Learn to Code - Codility

Rotate an array to the right by a given number of steps.

app.codility.com


나의 답안 - [66%] 정답

def solution(A):

    dic = dict()

    for v in A:
        if v not in dic.keys():
            dic[v] = 1
        else:
            dic[v] += 1

    answer = min(dic.items(), key=lambda k:k[1])

    return answer[0]

 

타인의 모범답안 - [100%] 정답

  • 비트연산을 통해서 element가 짝수인지 홀수인지 판명
from functools import reduce

def solution(A):

    return reduce(lambda x,y: x^y, A)
728x90
반응형

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

[Python] 3.3. TapeEquilibrium  (0) 2021.03.11
[Python] 3.2. PermMissingElem  (0) 2021.03.11
[Python] 3.1. FrogJmp  (0) 2021.03.07
[Python] 2.1. CyclicRotation  (0) 2021.03.06
[Python] 1.1. BinaryGap  (0) 2021.03.06

댓글