Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit fb498cd

Browse files
committedApr 18, 2025
Add solution #1526
1 parent 974cd40 commit fb498cd

File tree

2 files changed

+30
-1
lines changed

2 files changed

+30
-1
lines changed
 

‎README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# 1,347 LeetCode solutions in JavaScript
1+
# 1,348 LeetCode solutions in JavaScript
22

33
[https://leetcodejavascript.com](https://leetcodejavascript.com)
44

@@ -1166,6 +1166,7 @@
11661166
1523|[Count Odd Numbers in an Interval Range](./solutions/1523-count-odd-numbers-in-an-interval-range.js)|Easy|
11671167
1524|[Number of Sub-arrays With Odd Sum](./solutions/1524-number-of-sub-arrays-with-odd-sum.js)|Medium|
11681168
1525|[Number of Good Ways to Split a String](./solutions/1525-number-of-good-ways-to-split-a-string.js)|Medium|
1169+
1526|[Minimum Number of Increments on Subarrays to Form a Target Array](./solutions/1526-minimum-number-of-increments-on-subarrays-to-form-a-target-array.js)|Hard|
11691170
1528|[Shuffle String](./solutions/1528-shuffle-string.js)|Easy|
11701171
1534|[Count Good Triplets](./solutions/1534-count-good-triplets.js)|Easy|
11711172
1535|[Find the Winner of an Array Game](./solutions/1535-find-the-winner-of-an-array-game.js)|Medium|
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
/**
2+
* 1526. Minimum Number of Increments on Subarrays to Form a Target Array
3+
* https://leetcode.com/problems/minimum-number-of-increments-on-subarrays-to-form-a-target-array/
4+
* Difficulty: Hard
5+
*
6+
* You are given an integer array target. You have an integer array initial of the same size as
7+
* target with all elements initially zeros.
8+
*
9+
* In one operation you can choose any subarray from initial and increment each value by one.
10+
*
11+
* Return the minimum number of operations to form a target array from initial.
12+
*
13+
* The test cases are generated so that the answer fits in a 32-bit integer.
14+
*/
15+
16+
/**
17+
* @param {number[]} target
18+
* @return {number}
19+
*/
20+
var minNumberOperations = function(target) {
21+
let operations = target[0];
22+
for (let i = 1; i < target.length; i++) {
23+
if (target[i] > target[i - 1]) {
24+
operations += target[i] - target[i - 1];
25+
}
26+
}
27+
return operations;
28+
};

0 commit comments

Comments
 (0)
Please sign in to comment.