avatar
Published on

Codility - Distinct

Author
  • avatar
    Name
    yceffort

Distinct

๋ฌธ์ œ

๋ฐฐ์—ด A์•ˆ์— uniqueํ•œ ์ˆซ์ž๊ฐ€ ๋ช‡ ๊ฐœ ์žˆ๋Š”์ง€ ๋ฆฌํ„ดํ•˜๋ผ.

ํ’€์ด

function solution(A) {
  return [...new Set(A)].length
}

Set์„ ํ™œ์šฉํ•˜๋ฉด ์‰ฝ๊ฒŒ ํ’€ ์ˆ˜ ์žˆ๋‹ค. Set์ด ์•„๋‹ˆ๋”๋ผ๋„ object๋“ฑ์„ ํ™œ์šฉํ•ด๋ณด๋ฉด ๋œ๋‹ค.

https://app.codility.com/demo/results/training4VKM6Q-5SX/