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

728x90
๋ฐ˜์‘ํ˜•

๋ฌธ์ œ

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

 

Triangle coding task - Learn to Code - Codility

Determine whether a triangle can be built from a given set of edges.

app.codility.com

 


๋ฌธ์ œ ํ’€์ด

๋ฆฌ์ŠคํŠธ ๋‚ด์˜ ๊ฐ’๋“ค์„ ์กฐํ•ฉํ•˜์—ฌ, ์‚ผ๊ฐํ˜•์ด ๋˜๋Š” ๊ฒฝ์šฐ๊ฐ€ ์žˆ๋Š”์ง€ ํ™•์ธํ•˜๋Š” ๋ฌธ์ œ์ด๋‹ค.

 


์ฝ”๋“œ

def solution(A):
    A.sort()
    for i in range(len(A) - 2):
        if A[i] + A[i + 1] > A[i + 2]:
            return 1
    return 0
  • ์ฒ˜์Œ์—๋Š” ์Œ์ˆ˜์ธ ๊ฒฝ์šฐ๋ฅผ ์ƒ๊ฐํ•˜์ง€ ๋ชปํ•˜๊ณ  ์ œ์ถœํ•˜์˜€๋Š”๋ฐ, ๊ณฑํ•˜๊ธฐ ์ด๋ฏ€๋กœ ์Œ์ˆ˜์ธ ๊ฒฝ์šฐ๋„ ๊ณ ๋ คํ•˜์—ฌ์•ผ ํ•œ๋‹ค.

728x90
๋ฐ˜์‘ํ˜•
๋Œ“๊ธ€
๊ธ€ ๋ณด๊ด€ํ•จ
์ตœ๊ทผ์— ์˜ฌ๋ผ์˜จ ๊ธ€
์ตœ๊ทผ์— ๋‹ฌ๋ฆฐ ๋Œ“๊ธ€