ํฐ์คํ ๋ฆฌ ๋ทฐ
๐จ๐ป ์ฝ๋ฉํ
์คํธ/Codility
Lesson 10: Prime and composite numbers → Peeks
dirmathfl 2020. 6. 15. 18:33728x90
๋ฐ์ํ
๋ฌธ์
๋ฌธ์ ํ์ด
๊ฐ ๊ตฌ๊ฐ์ ๋๋ ๋, ๊ฐ ๊ตฌ๊ฐ๋ง๋ค peek๋ฅผ ํฌํจํ์ฌ์ผ ํ๋ค. ๋ฌธ์ ๋ฅผ ํด๊ฒฐํ๊ธฐ ์ํด peek์ธ ๊ตฌ๊ฐ์ ์ฐพ๋๋ค.
๋๋ ์ ์๋ ๊ตฌ๊ฐ์ ์ฃผ์ด์ง A ๋ฆฌ์คํธ์ ๊ธธ์ด์ ์ฝ์๋ฅผ ์๋ฏธํ๋ ๊ฒ์ด๋ฏ๋ก, ์ฝ์์ ๋ํ ๊ตฌ๊ฐ์ ํ์ธํ๊ณ peek๋ฅผ ํฌํจํ๋ ์ง ํ์ธํ๋ค.
์ฝ๋
def solution(A):
peeks = []
length = len(A)
for i in range(1, length - 1):
if A[i - 1] < A[i] > A[i + 1]:
peeks.append(i)
cnt = len(peeks)
if not cnt:
return 0
for i in range(cnt, 0, -1):
if length % i == 0:
block_size = length // i
check = [False] * i
for peek in peeks:
idx = peek // block_size
if not check[idx]:
check[idx] = True
if all(check):
return i
return 0
728x90
๋ฐ์ํ
'๐จโ๐ป ์ฝ๋ฉํ ์คํธ > Codility' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
Lesson 10: Prime and composite numbers โ Min Perimeter Rectangle (0) | 2020.06.14 |
---|---|
Lesson 10: Prime and composite numbers โ Count Factors (0) | 2020.06.14 |
Lesson 9: Maximum Slice Problem โ Max Slice Sum (0) | 2020.06.11 |
Lesson 9: Maximum Slice Problem โ Max Profit (0) | 2020.06.11 |
Lesson 8: Leader โ Equil Leader (0) | 2020.06.10 |
๋๊ธ
๊ธ ๋ณด๊ดํจ
์ต๊ทผ์ ์ฌ๋ผ์จ ๊ธ
์ต๊ทผ์ ๋ฌ๋ฆฐ ๋๊ธ