Leetcode_easy985. Sum of Even Numbers After Queries

Posted happyamyhope

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Leetcode_easy985. Sum of Even Numbers After Queries相关的知识,希望对你有一定的参考价值。

problem

985. Sum of Even Numbers After Queries

class Solution 
public:
    vector<int> sumEvenAfterQueries(vector<int>& A, vector<vector<int>>& queries) 
        vector<int> res;
        int sum = 0;
        for(auto a:A) if(a%2==0) sum +=a;
        for(auto query:queries)
        
            if(A[query[1]]%2==0 ) sum-=A[query[1]];
            A[query[1]] += query[0];
            if(A[query[1]]%2==0) sum +=A[query[1]];
            res.push_back(sum);
        
        return res;
    
;

 

参考

1. Leetcode_easy_985. Sum of Even Numbers After Queries;

以上是关于Leetcode_easy985. Sum of Even Numbers After Queries的主要内容,如果未能解决你的问题,请参考以下文章

[Solution] 985. Sum of Even Numbers After Queries

Leetcode 985. Sum of Even Numbers After Queries

LeetCode 985 Sum of Even Numbers After Queries ????????????

leetcode985. Sum of Even Numbers After Queries

LC 985. Sum of Even Numbers After Queries

Leetcode 985. Sum of Even Numbers After Queries