ํฐ์คํ ๋ฆฌ ๋ทฐ
๐จ๐ป ์ฝ๋ฉํ
์คํธ/Codility
Lesson 3: Time Complexity → Perm Missing Elem
dirmathfl 2020. 6. 6. 19:14728x90
๋ฐ์ํ
๋ฌธ์
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
๋ฐ์ํ
'๐จโ๐ป ์ฝ๋ฉํ ์คํธ > Codility' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
Lesson 4: Counting Elements โ Frog River One (0) | 2020.06.06 |
---|---|
Lesson 3: Complexity โ Tape Equilibrium (0) | 2020.06.06 |
Lesson 3: Time Complexity โ Flog Jmp (0) | 2020.06.06 |
Lesson 2: Arrays -> Odd Occurrences In Array (0) | 2020.06.06 |
Lesson 2: Arrays โ Cyclic Rotation (0) | 2020.06.06 |
๋๊ธ
๊ธ ๋ณด๊ดํจ
์ต๊ทผ์ ์ฌ๋ผ์จ ๊ธ
์ต๊ทผ์ ๋ฌ๋ฆฐ ๋๊ธ