Class Solution
java.lang.Object
g1601_1700.s1664_ways_to_make_a_fair_array.Solution
1664 - Ways to Make a Fair Array.<p>Medium</p>
<p>You are given an integer array <code>nums</code>. You can choose <strong>exactly one</strong> index ( <strong>0-indexed</strong> ) and remove the element. Notice that the index of the elements may change after the removal.</p>
<p>For example, if <code>nums = [6,1,7,4,1]</code>:</p>
<ul>
<li>Choosing to remove index <code>1</code> results in <code>nums = [6,7,4,1]</code>.</li>
<li>Choosing to remove index <code>2</code> results in <code>nums = [6,1,4,1]</code>.</li>
<li>Choosing to remove index <code>4</code> results in <code>nums = [6,1,7,4]</code>.</li>
</ul>
<p>An array is <strong>fair</strong> if the sum of the odd-indexed values equals the sum of the even-indexed values.</p>
<p>Return the <em><strong>number</strong> of indices that you could choose such that after the removal,</em> <code>nums</code> <em>is <strong>fair</strong>.</em></p>
<p><strong>Example 1:</strong></p>
<p><strong>Input:</strong> nums = [2,1,6,4]</p>
<p><strong>Output:</strong> 1</p>
<p><strong>Explanation:</strong></p>
<p>Remove index 0: [1,6,4] -> Even sum: 1 + 4 = 5. Odd sum: 6. Not fair.</p>
<p>Remove index 1: [2,6,4] -> Even sum: 2 + 4 = 6. Odd sum: 6. Fair.</p>
<p>Remove index 2: [2,1,4] -> Even sum: 2 + 4 = 6. Odd sum: 1. Not fair.</p>
<p>Remove index 3: [2,1,6] -> Even sum: 2 + 6 = 8. Odd sum: 1. Not fair.</p>
<p>There is 1 index that you can remove to make nums fair.</p>
<p><strong>Example 2:</strong></p>
<p><strong>Input:</strong> nums = [1,1,1]</p>
<p><strong>Output:</strong> 3</p>
<p><strong>Explanation:</strong> You can remove any index and the remaining array is fair.</p>
<p><strong>Example 3:</strong></p>
<p><strong>Input:</strong> nums = [1,2,3]</p>
<p><strong>Output:</strong> 0</p>
<p><strong>Explanation:</strong> You cannot make a fair array after removing any index.</p>
<p><strong>Constraints:</strong></p>
<ul>
<li><code>1 <= nums.length <= 10<sup>5</sup></code></li>
<li><code>1 <= nums[i] <= 10<sup>4</sup></code></li>
</ul>
-
Constructor Summary
Constructors -
Method Summary
-
Constructor Details
-
Solution
public Solution()
-
-
Method Details
-
waysToMakeFair
public int waysToMakeFair(int[] nums)
-