251. OddOccurrencesInArray

아현·2021년 8월 14일
0

Algorithm

목록 보기
263/400
post-custom-banner



1. JavaScript


function solution(A) {
    // write your code in JavaScript (Node.js 8.9.4)
    let element = new Set();
    
    for(let i in A){
        if(!element.has(A[i])){
            element.add(A[i]);
        }
        else{
            element.delete(A[i]);
        }
    }
    
    const result = [...element];
    return result[0];
}




2. Python


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])
profile
For the sake of someone who studies computer science
post-custom-banner

0개의 댓글