You are viewing a single comment's thread. Return to all comments →
Python #Python code
def maximumPerimeterTriangle(sticks): sticks.sort(reverse=True) n = len(sticks) maxp = -1 sideIndex = -1 resTuple = (0, 0, 0) for i in range(n-2): a = sticks[i] b = sticks[i+1] c = sticks[i+2] if (a + b > c and b + c > a and c + a > b): if ((a + b + c)>maxp): maxp = a + b + c resTuple = a, b, c sideIndex = i print("i: ", i, "sideIndex: ", sideIndex) elif (a+b+c) == maxp: if (resTuple[2] < c): maxp = a + b + c sideIndex = i resTuple = a, b, c print("i: ", i, "sideIndex: ", sideIndex) elif (resTuple[2] == c): if resTuple[0] < a: maxp = a + b + c sideIndex = i resTuple = a, b, c print("i: ", i, "sideIndex: ", sideIndex) if maxp >=0: return (sticks[sideIndex +2], sticks[sideIndex+1], sticks[sideIndex]) else: return -1
Seems like cookies are disabled on this browser, please enable them to open this website
Maximum Perimeter Triangle
You are viewing a single comment's thread. Return to all comments →
Python #Python code