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

728x90
๋ฐ˜์‘ํ˜•

๋ฌธ์ œ

https://app.codility.com/programmers/lessons/3-time_complexity/perm_missing_elem/

๋ฐฐ์—ด์— ์žˆ๋Š” ์›์†Œ๋“ค์˜ ์ˆ˜๋Š” N์ด๊ณ  ๊ทธ ์ค‘ ์—†๋Š” ์›์†Œ๋ฅผ ์ฐพ์•„์•ผ ํ•œ๋‹ค. ์˜ˆ๋ฅผ ๋“ค์–ด 1, 2, 3, 5๋ผ๋ฉด ๋น ์ง„ ์ˆ˜๋Š” 4์ด๋‹ค.

๋ฌธ์ œ ํ’€์ด

Counter๋ฅผ ํ™œ์šฉํ•˜๋ฉด ๋ฌธ์ œ๋ฅผ ์‰ฝ๊ฒŒ ํ•ด๊ฒฐํ•  ์ˆ˜ ์žˆ๋‹ค.

์ฝ”๋“œ

from collections import Counter


def solution(A):
    check = [num + 1 for num in range(len(A) + 1)]
    return list(Counter(check) - Counter(A))[0]
728x90
๋ฐ˜์‘ํ˜•
๋Œ“๊ธ€
๊ธ€ ๋ณด๊ด€ํ•จ
์ตœ๊ทผ์— ์˜ฌ๋ผ์˜จ ๊ธ€
์ตœ๊ทผ์— ๋‹ฌ๋ฆฐ ๋Œ“๊ธ€