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

728x90
๋ฐ˜์‘ํ˜•

๋ฌธ์ œ

https://app.codility.com/programmers/lessons/6-sorting/max_product_of_three/

 

MaxProductOfThree coding task - Learn to Code - Codility

Maximize A[P] * A[Q] * A[R] for any triplet (P, Q, R).

app.codility.com

 


๋ฌธ์ œ ํ’€์ด

๋ฆฌ์ŠคํŠธ์˜ ๋‚ด์˜ ๊ฐ’๋“ค ์ค‘ 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
๋ฐ˜์‘ํ˜•
๋Œ“๊ธ€
๊ธ€ ๋ณด๊ด€ํ•จ
์ตœ๊ทผ์— ์˜ฌ๋ผ์˜จ ๊ธ€
์ตœ๊ทผ์— ๋‹ฌ๋ฆฐ ๋Œ“๊ธ€