You are viewing a single comment's thread. Return to all comments →
Java, O(n log n)
public static List<Integer> maximumPerimeterTriangle(List<Integer> sticks) { Collections.sort(sticks, Collections.reverseOrder()); for (int i = 0; i <= sticks.size() - 3; i++) { int a = sticks.get(i); int b = sticks.get(i + 1); int c = sticks.get(i + 2); if (a < b + c) { return Arrays.asList(c, b, a); } } return Collections.singletonList(-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 →
Java, O(n log n)