← 返回 ibm 的题目列表Minimum Hits Needed
类型:online_judge
Minimum Hits Needed
Given an integer array targets, where each element represents a target that needs to be hit until its durability reaches zero. A target can only be completely destroyed in one hit when its current durability is shared by a range hit. The task is to find the minimum number of hits needed to destroy all targets.
Input:
An integer array targets representing each target's durability.
Output:
One integer representing the minimum number of hits needed to destroy all targets.
Example:
Input: targets = [2, 2, 3, 1]
Output: 3
Explanation: You can hit:
First hit, range [0, 1], targets [2, 2] are destroyed.
Second hit, range [2, 2], target [3] is destroyed.
Third hit, range [3, 3], target [1] is destroyed.
Constraints:
1 <= targets.length <= 10^5
1 <= targets[i] <= 10^9
Example
Input
[2, 2, 3, 1]