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;
完
原文地址:https://www.cnblogs.com/happyamyhope/p/11316944.html
时间: 2024-11-10 13:50:37