java.lang.Object
g0901_1000.s0985_sum_of_even_numbers_after_queries.Solution

public class Solution extends Object
985 - Sum of Even Numbers After Queries.<p>Medium</p> <p>You are given an integer array <code>nums</code> and an array <code>queries</code> where <code>queries[i] = [val<sub>i</sub>, index<sub>i</sub>]</code>.</p> <p>For each query <code>i</code>, first, apply <code>nums[index<sub>i</sub>] = nums[index<sub>i</sub>] + val<sub>i</sub></code>, then print the sum of the even values of <code>nums</code>.</p> <p>Return <em>an integer array</em> <code>answer</code> <em>where</em> <code>answer[i]</code> <em>is the answer to the</em> <code>i<sup>th</sup></code> <em>query</em>.</p> <p><strong>Example 1:</strong></p> <p><strong>Input:</strong> nums = [1,2,3,4], queries = [[1,0],[-3,1],[-4,0],[2,3]]</p> <p><strong>Output:</strong> [8,6,2,4]</p> <p><strong>Explanation:</strong> At the beginning, the array is [1,2,3,4].</p> <p>After adding 1 to nums[0], the array is [2,2,3,4], and the sum of even values is 2 + 2 + 4 = 8.</p> <p>After adding -3 to nums[1], the array is [2,-1,3,4], and the sum of even values is 2 + 4 = 6.</p> <p>After adding -4 to nums[0], the array is [-2,-1,3,4], and the sum of even values is -2 + 4 = 2.</p> <p>After adding 2 to nums[3], the array is [-2,-1,3,6], and the sum of even values is -2 + 6 = 4.</p> <p><strong>Example 2:</strong></p> <p><strong>Input:</strong> nums = [1], queries = [[4,0]]</p> <p><strong>Output:</strong> [0]</p> <p><strong>Constraints:</strong></p> <ul> <li><code>1 <= nums.length <= 10<sup>4</sup></code></li> <li><code>-10<sup>4</sup> <= nums[i] <= 10<sup>4</sup></code></li> <li><code>1 <= queries.length <= 10<sup>4</sup></code></li> <li><code>-10<sup>4</sup> <= val<sub>i</sub> <= 10<sup>4</sup></code></li> <li><code>0 <= index<sub>i</sub> < nums.length</code></li> </ul>
  • Constructor Details

    • Solution

      public Solution()
  • Method Details

    • sumEvenAfterQueries

      public int[] sumEvenAfterQueries(int[] nums, int[][] queries)