Skip to content

Commit 9781a2c

Browse files
committed
Add solution #3010
1 parent 7cca561 commit 9781a2c

File tree

2 files changed

+33
-0
lines changed

2 files changed

+33
-0
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2127,6 +2127,7 @@
21272127
2999|[Count the Number of Powerful Integers](./solutions/2999-count-the-number-of-powerful-integers.js)|Hard|
21282128
3002|[Maximum Size of a Set After Removals](./solutions/3002-maximum-size-of-a-set-after-removals.js)|Medium|
21292129
3005|[Count Elements With Maximum Frequency](./solutions/3005-count-elements-with-maximum-frequency.js)|Easy|
2130+
3010|[Divide an Array Into Subarrays With Minimum Cost I](./solutions/3010-divide-an-array-into-subarrays-with-minimum-cost-i.js)|Easy|
21302131
3024|[Type of Triangle](./solutions/3024-type-of-triangle.js)|Easy|
21312132
3042|[Count Prefix and Suffix Pairs I](./solutions/3042-count-prefix-and-suffix-pairs-i.js)|Easy|
21322133
3066|[Minimum Operations to Exceed Threshold Value II](./solutions/3066-minimum-operations-to-exceed-threshold-value-ii.js)|Medium|
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
/**
2+
* 3010. Divide an Array Into Subarrays With Minimum Cost I
3+
* https://leetcode.com/problems/divide-an-array-into-subarrays-with-minimum-cost-i/
4+
* Difficulty: Easy
5+
*
6+
* You are given an array of integers nums of length n.
7+
*
8+
* The cost of an array is the value of its first element. For example, the cost of [1,2,3]
9+
* is 1 while the cost of [3,4,1] is 3.
10+
*
11+
* You need to divide nums into 3 disjoint contiguous subarrays.
12+
*
13+
* Return the minimum possible sum of the cost of these subarrays.
14+
*/
15+
16+
/**
17+
* @param {number[]} nums
18+
* @return {number}
19+
*/
20+
var minimumCost = function(nums) {
21+
const n = nums.length;
22+
let result = Infinity;
23+
24+
for (let i = 1; i < n - 1; i++) {
25+
for (let j = i + 1; j < n; j++) {
26+
const cost = nums[0] + nums[i] + nums[j];
27+
result = Math.min(result, cost);
28+
}
29+
}
30+
31+
return result;
32+
};

0 commit comments

Comments
 (0)