You are given an integer array nums, where nums[i] represents the points scored in the ith game.
There are exactly two players. Initially, the first player is active and the second player is inactive.
The following rules apply sequentially for each game i:
nums[i] is odd, the active and inactive players swap roles.5, 11, 17, ...), the active and inactive players swap roles.ith game and gains nums[i] points.Return the score difference, defined as the first player's total score minus the second player's total score.
Example 1:
Input: nums = [1,2,3]
Output: 0
Explanation:
nums[0] = 1 point.nums[1] = 2 points.nums[2] = 3 points.3 - 3 = 0.Example 2:
Input: nums = [2,4,2,1,2,1]
Output: 4
Explanation:
2 + 4 + 2 = 8 points.nums[3] = 1 point.nums[4] = 2 points.nums[5] = 1 point.8 - 4 = 4.Example 3:
Input: nums = [1]
Output: -1
Explanation:
nums[0] = 1 point.0 - 1 = -1.
Constraints:
1 <= nums.length <= 10001 <= nums[i] <= 1000Solutions for this problem are being prepared.
Try solving it yourselfPractice Find the Score Difference in a Game with our built-in code editor and test cases.
Practice on FleetCodePractice this problem
Open in Editor