-
Notifications
You must be signed in to change notification settings - Fork 1.3k
/
Copy path_2908.java
25 lines (23 loc) · 885 Bytes
/
_2908.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
package com.fishercoder.solutions.thirdthousand;
public class _2908 {
public static class Solution1 {
public int minimumSum(int[] nums) {
int minSum = Integer.MAX_VALUE;
for (int i = 0; i < nums.length - 2; i++) {
for (int j = i + 1; j < nums.length - 1; j++) {
if (nums[i] < nums[j]) {
int sum = nums[i] + nums[j];
for (int k = j + 1; k < nums.length; k++) {
if (nums[k] < nums[j]) {
sum += nums[k];
minSum = Math.min(minSum, sum);
sum -= nums[k];
}
}
}
}
}
return minSum == Integer.MAX_VALUE ? -1 : minSum;
}
}
}