문제
코드
삼각형의 전제조건 a + b > c 를 구현하는 문제.
combination으로 모든 가능한 조합을 생성한 후, 전제조건에 맞는 목록들만 추출해낸다.
def maximumPerimeterTriangle(sticks):
temp = []
a = list(combinations(sticks, 3))
for i in a:
if sum(i) - max(i) > max(i):
temp.append(i)
temp.sort(key=lambda x: sum(x))
if temp:
return sorted(temp[-1])
else:
return [-1]