1. Description:
Notes:
2. Examples:
3.Solutions:
1 /** 2 * Created by sheepcore on 2019-02-24 3 */ 4 class Solution { 5 public int[] sumEvenAfterQueries(int[] A, int[][] queries) { 6 int sum = 0; 7 for (int a : A) { 8 if (a % 2 == 0) 9 sum += a; 10 } // sum of even #s. 11 int[] ans = new int[queries.length]; 12 for (int i = 0; i < ans.length; ++i) { 13 int idx = queries[i][1]; 14 if (A[idx] % 2 == 0) { 15 sum -= A[idx]; 16 } // from 1) and 2) 17 A[idx] += queries[i][0]; 18 if (A[idx] % 2 == 0) { 19 sum += A[idx]; 20 } // from 2) and 3) 21 ans[i] = sum; 22 } 23 return ans; 24 } 25 }