ํ‹ฐ์Šคํ† ๋ฆฌ ๋ทฐ

728x90
๋ฐ˜์‘ํ˜•

๋ฌธ์ œ

https://app.codility.com/programmers/lessons/6-sorting/distinct/

 

Distinct coding task - Learn to Code - Codility

Compute number of distinct values in an array.

app.codility.com

 


๋ฌธ์ œ ํ’€์ด

๋ฆฌ์ŠคํŠธ ๋‚ด์— ์ค‘๋ณต๋˜๋Š” ์›์†Œ๋“ค์„ ์ œ์™ธํ•˜๊ณ  ๊ตฌ๋ถ„๋˜๋Š” ๊ฐ’๋“ค์ด ๋ช‡๊ฐœ๊ฐ€ ์žˆ๋Š”์ง€ ๋ฐ˜ํ™˜ํ•˜๋Š” ๋ฌธ์ œ์ด๋‹ค.

 


์ฝ”๋“œ

def solution(A):
    return len(set(A))
  • set์„ ํ†ตํ•ด ์ค‘๋ณต ๊ฐ’์„ ์ œ์™ธํ•˜๊ณ  ๊ตฌ๋ถ„๋˜๋Š” ๊ฐ’์„ ๊ตฌํ•  ์ˆ˜ ์žˆ๋‹ค.

728x90
๋ฐ˜์‘ํ˜•
๋Œ“๊ธ€
๊ธ€ ๋ณด๊ด€ํ•จ
์ตœ๊ทผ์— ์˜ฌ๋ผ์˜จ ๊ธ€
์ตœ๊ทผ์— ๋‹ฌ๋ฆฐ ๋Œ“๊ธ€