#8Battle for the Kingdom
You are the commander of a powerful kingdom defending your territory from invading enemies. There are several battlefields arranged in a straight line, and each battlefield offers a certain amount of war resources if you win the battle.
However, your army needs time to recover after every battle.
You cannot fight two consecutive battles. If you fight at one battlefield, you must skip the next battlefield to allow your soldiers to rest.
Given an integer array nums, where nums[i] represents the amount of resources you can gain by winning the i-th battle, return the maximum resources you can collect without fighting two consecutive battles.
Examples
Example 1
Input: nums = [10, 5, 15, 5, 25]
Output: 50
Explanation: Fight Battle 1, Battle 3, and Battle 5. Total resources = 10 + 15 + 25 = 50.
Example 2
Input: nums = [6, 14, 8, 20, 5]
Output: 34
Explanation: Fight Battle 1 and gain 6 resources. Skip Battle 2. Fight Battle 4 and gain 20 resources. Skip Battle 5. However, a better strategy is to fight Battle 2 and Battle 4: 14 + 20 = 34 resources.
Constraints
- 0 <= nums[i] <= 10^5
- 1 <= nums.length <= 500
