← 返回 amazon 的题目列表Game Minimum Health
类型:online_judge
Implement a function getMinimumHealth that takes two parameters: power and armor. Power is an array representing a series of attack damages. Armor is an integer representing the maximum damage value that armor can mitigate. The goal is to calculate the minimum initial health needed to ensure that the health is greater than zero after the last attack.
Test Cases:
Example 1:
Input: power = [2, 7, 4], armor = 5
Output: 11
Example 2:
Input: power = [1, 3, 2, 2, 4], armor = 3
Output: 13
Constraints:
1 <= power.length <= 10^5
1 <= power[i] <= 10^5
0 <= armor <= 10^5
Requirements: Write an efficient algorithm.
Example
Input
power = [2, 7, 4], armor = 5