262. Distinct

아현·2021년 8월 15일
0

Algorithm

목록 보기
274/400



1. JavaScript


정해


// you can write to stdout for debugging purposes, e.g.
// console.log('this is a debug message');

function solution(A) {
    // write your code in JavaScript (Node.js 8.9.4)

    let values = new Set();
    
    for(let i in A){
        values.add(A[i]);
    }
    
    return values.size;
}



runtime error


// you can write to stdout for debugging purposes, e.g.
// console.log('this is a debug message');

function solution(A) {
    // write your code in JavaScript (Node.js 8.9.4)
    let count = Array(Math.max(...A)).fill(0);
    for(let a of A){
        count[a]++;
    }

    return count.findIndex(1);

}



2. Python



# you can write to stdout for debugging purposes, e.g.
# print("this is a debug message")

def solution(A):
    # write your code in Python 3.6
    list = set(A)
    return len(list)


    

profile
For the sake of someone who studies computer science

0개의 댓글