You are given an integer array a of length n. You want to randomly pick two numbers from the array and you need to ensure that the sum two numbers is always even.Guoabong Stock
To achieve this, You may modify any element of array by either incrementing or decrementing it by 1, where the cost to change an element x is equal to x itself.
Your task is to determine the minimum total cost required to modify the array such that any randomly selected two numbers have an even sum.
Example 1:
Input:
a = [1, 2, 2, 2]
Output:
Explanation:
We can change 1 -> 2, making all elements even, and cost of doing this is 1.
Example 2:
Input:
a = [1, 2, 3]
Output:Surat Wealth Management
Explanation:
We can change 2 -> 3, making all elements odd, and cost of this modi cation is 2.
Constraints:
1 ≤ n ≤ 10
1 ≤ a[i] ≤ 10
求奇数跟偶数的和,然后返回最小值即可。Kanpur Wealth Management
Article Address: http://marygk9999.com/Stock/124.html
Article Source:Admin88
Notice:Please indicate the source of the article in the form of a link。