985. Sum of Even Numbers After Queries Medium
1/**
2 * [985] Sum of Even Numbers After Queries
3 *
4 * You are given an integer array nums and an array queries where queries[i] = [vali, indexi].
5 * For each query i, first, apply nums[indexi] = nums[indexi] + vali, then print the sum of the even values of nums.
6 * Return an integer array answer where answer[i] is the answer to the i^th query.
7 *
8 * Example 1:
9 *
10 * Input: nums = [1,2,3,4], queries = [[1,0],[-3,1],[-4,0],[2,3]]
11 * Output: [8,6,2,4]
12 * Explanation: At the beginning, the array is [1,2,3,4].
13 * After adding 1 to nums[0], the array is [2,2,3,4], and the sum of even values is 2 + 2 + 4 = 8.
14 * After adding -3 to nums[1], the array is [2,-1,3,4], and the sum of even values is 2 + 4 = 6.
15 * After adding -4 to nums[0], the array is [-2,-1,3,4], and the sum of even values is -2 + 4 = 2.
16 * After adding 2 to nums[3], the array is [-2,-1,3,6], and the sum of even values is -2 + 6 = 4.
17 *
18 * Example 2:
19 *
20 * Input: nums = [1], queries = [[4,0]]
21 * Output: [0]
22 *
23 *
24 * Constraints:
25 *
26 * 1 <= nums.length <= 10^4
27 * -10^4 <= nums[i] <= 10^4
28 * 1 <= queries.length <= 10^4
29 * -10^4 <= vali <= 10^4
30 * 0 <= indexi < nums.length
31 *
32 */
33pub struct Solution {}
34
35// problem: https://leetcode.com/problems/sum-of-even-numbers-after-queries/
36// discuss: https://leetcode.com/problems/sum-of-even-numbers-after-queries/discuss/?currentPage=1&orderBy=most_votes&query=
37
38// submission codes start here
39
40impl Solution {
41 pub fn sum_even_after_queries(nums: Vec<i32>, queries: Vec<Vec<i32>>) -> Vec<i32> {
42 vec![]
43 }
44}
45
46// submission codes end
47
48#[cfg(test)]
49mod tests {
50 use super::*;
51
52 #[test]
53 fn test_985() {
54 }
55}
56
Back
© 2025 bowen.ge All Rights Reserved.