[Codility] OddOccurrencesInArray

hyeon·2021년 2월 19일
0

Codility

목록 보기
3/18

from collections import defaultdict
def solution(A):
    # write your code in Python 3.6
    storage = []
    A.sort()
    for a in A:
        if a not in storage:
            storage.append(a)
        else :
            storage.remove(a)
    return storage[0]

others

def test3(A):
    if len(A) == 1:
        return A[0]

    A = sorted(A)
    print(A)
    for i in range(0, len(A), 2):
        if i+1 == len(A):
            return A[i]
        if A[i] != A[i+1]:
            return A[i]

test3([1,2,1,2,3])
def solution(A):
  return reduce(lambda x,y: x^y, A)
profile
바스락바스락

0개의 댓글