You are given an array of integers nums.
The alternating sum of the array is calculated by adding the elements at even indices and subtracting the elements at odd indices.
Formally,
Alternating Sum=nums[0]−nums[1]+nums[2]−nums[3]+...
Your task is to return the integer result of this alternating sum.
Input: nums = [15, 3, 9]
Output: 21
Input: nums = [2, 4, 6, 8, 10]
Output: 6
Accepted:
Submission: