Skip to content

Commit acd2e4e

Browse files
authored
Create Divide an Array Into Subarrays With Minimum Cost I.java
1 parent 8c79499 commit acd2e4e

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
class Solution {
2+
public int minimumCost(int[] nums) {
3+
int minOne = Integer.MAX_VALUE;
4+
int minTwo = Integer.MAX_VALUE;
5+
for (int i = 1; i < nums.length; i++) {
6+
if (nums[i] < minOne) {
7+
minTwo = minOne;
8+
minOne = nums[i];
9+
} else if (nums[i] < minTwo) {
10+
minTwo = nums[i];
11+
}
12+
}
13+
return nums[0] + minOne + minTwo;
14+
}
15+
}

0 commit comments

Comments
 (0)