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

728x90
๋ฐ˜์‘ํ˜•

๋ฌธ์ œ

https://app.codility.com/programmers/lessons/4-counting_elements/missing_integer/

๋ฆฌ์ŠคํŠธ๊ฐ€ ์ฃผ์–ด์ง€๋ฉด, ๋ฆฌ์ŠคํŠธ์˜ ์กด์žฌํ•˜์ง€ ์•Š๋Š” ๊ฐ’์„ ์ฐพ๊ฑฐ๋‚˜ ๋ฆฌ์ŠคํŠธ์— ๊ฐ’์ด ๋ชจ๋‘ ์กด์žฌํ•˜๋Š” ๊ฒฝ์šฐ์—๋Š” ๋‹ค์Œ์˜ ์ˆ˜๋ฅผ ๋ฐ˜ํ™˜ํ•œ๋‹ค. ๋ฆฌ์ŠคํŠธ์— ์Œ์ˆ˜๋งŒ ์กด์žฌํ•˜๋Š” ๊ฒฝ์šฐ์—๋Š” 1์„ ๋ฐ˜ํ™˜ํ•œ๋‹ค.

๋ฌธ์ œ ํ’€์ด

์ •๋ ฌํ•˜์ง€ ์•Š๊ณ  ๋ฌธ์ œ๋ฅผ ํ’€๋ ค๊ณ  ํ–ˆ์„๋•Œ๋Š” ์ฒดํฌ ๋ฆฌ์ŠคํŠธ๋ฅผ ํ™œ์šฉํ•˜๊ณ , ์ฝ”๋“œ๋„ ๋ณด๊ธฐ ํ‰ํ•˜๊ฒŒ ๋ณ€ํ–ˆ๋‹ค. ํ•˜์ง€๋งŒ ์ •๋ ฌ์„ ์‚ฌ์šฉํ•˜๋ฉด ์•„์ฃผ ๊ฐ„๋‹จํ•œ๊ฒŒ ๋ฌธ์ œ๋ฅผ ํ•ด๊ฒฐํ•  ์ˆ˜ ์žˆ๋‹ค.

์ฝ”๋“œ

def solution(A):
    sort = sorted(A)
    lost = 1
    for num in sort:
        if num == lost:
            lost += 1
    return lost
728x90
๋ฐ˜์‘ํ˜•
๋Œ“๊ธ€
๊ธ€ ๋ณด๊ด€ํ•จ
์ตœ๊ทผ์— ์˜ฌ๋ผ์˜จ ๊ธ€
์ตœ๊ทผ์— ๋‹ฌ๋ฆฐ ๋Œ“๊ธ€