ํฐ์คํ ๋ฆฌ ๋ทฐ
๐จ๐ป ์ฝ๋ฉํ
์คํธ/Codility
Lesson 6: Sorting → Max Product Of Three
dirmathfl 2020. 6. 8. 19:15728x90
๋ฐ์ํ
๋ฌธ์
https://app.codility.com/programmers/lessons/6-sorting/max_product_of_three/
๋ฌธ์ ํ์ด
๋ฆฌ์คํธ์ ๋ด์ ๊ฐ๋ค ์ค 3๊ฐ๋ฅผ ์ ํํ์ฌ ๊ณฑํ์์ ๋ ๊ฐ์ฅ ํฐ ๊ฐ์ด ๋๋ ๊ฒฝ์ฐ๋ฅผ ์ฐพ๋ ๋ฌธ์ ์ด๋ค.
์ฝ๋
def solution(A):
A.sort()
max_plus = A[-1] * A[-2] * A[-3]
max_minus = A[-1] * A[0] * A[1]
return max(max_plus, max_minus)
-
์ฒ์์๋ ์์์ธ ๊ฒฝ์ฐ๋ฅผ ์๊ฐํ์ง ๋ชปํ๊ณ ์ ์ถํ์๋๋ฐ, ๊ณฑํ๊ธฐ ์ด๋ฏ๋ก ์์์ธ ๊ฒฝ์ฐ๋ ๊ณ ๋ คํ์ฌ์ผ ํ๋ค.
728x90
๋ฐ์ํ
'๐จโ๐ป ์ฝ๋ฉํ ์คํธ > Codility' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
Lesson 7: Stacks and Queues โ Brackets (0) | 2020.06.09 |
---|---|
Lesson 6: Sorting โ Triangle (0) | 2020.06.08 |
Lesson 6: Sorting โ Distinct (0) | 2020.06.08 |
Lesson 5: Prefix Sums โ Passing Cars (0) | 2020.06.08 |
Lesson 5: Prefix Sums โ Min Avg Two Slice (0) | 2020.06.08 |
๋๊ธ
๊ธ ๋ณด๊ดํจ
์ต๊ทผ์ ์ฌ๋ผ์จ ๊ธ
์ต๊ทผ์ ๋ฌ๋ฆฐ ๋๊ธ