You are viewing a single comment's thread. Return to all comments →
public static List<Integer> maximumPerimeterTriangle(List<Integer> sticks) { Collections.sort(sticks); int longerPerimeter = Integer.MIN_VALUE; List<Integer> answer = Collections.singletonList(-1); for (int i = 0; i < sticks.size() - 2; i++) { if (sticks.get(i) + sticks.get(i + 1) > sticks.get(i + 2)) { if (sticks.get(i) + sticks.get(i + 1) + sticks.get(i + 2) > longerPerimeter) { longerPerimeter = sticks.get(i) + sticks.get(i + 1) + sticks.get(i + 2); answer = Arrays.asList(sticks.get(i), sticks.get(i + 1), sticks.get(i + 2)); } } } return answer; }
Maximum Perimeter Triangle
You are viewing a single comment's thread. Return to all comments →