LeetCode 985 Sum of Even Numbers After Queries ????????????
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了LeetCode 985 Sum of Even Numbers After Queries ????????????相关的知识,希望对你有一定的参考价值。
?????????ace ?????? etc app ?????? family ?????? ?????? pac
????????????
We have an array A
of integers, and an array queries
of queries.
For the i
-th query val = queries[i][0], index = queries[i][1]
, we add val to A[index]
. Then, the answer to the i
-th query is the sum of the even values of A
.
(Here, the given index = queries[i][1]
is a 0-based index, and each query permanently modifies the array A
.)
Return the answer to all queries. Your answer
array should have answer[i]
as the answer to the i
-th query.
?????????????????????
??????????????????????????????A?????????query?????????query?????????????????????????????????????????????????????????????????????????????????????????????????????????A????????????????????????????????????????????????A????????????????????????A?????????????????????????????????????????????query???????????????????????????A????????????????????????????????????query??????????????????????????????A???????????????????????????????????????
python??????
class Solution:
def sumEvenAfterQueries(self, A: ???List[int]???, queries: ???List[List[int]]???) -> ???List[int]???:
res = []
s = sum([i for i in A if i % 2 == 0])
for v, i in queries:
if A[i] % 2 == 0:
s -= A[i]
A[i] += v
if A[i] % 2 == 0:
s += A[i]
res.append(s)
return res
以上是关于LeetCode 985 Sum of Even Numbers After Queries ????????????的主要内容,如果未能解决你的问题,请参考以下文章
leetcode985. Sum of Even Numbers After Queries
Leetcode_easy985. Sum of Even Numbers After Queries
Leetcode 985. Sum of Even Numbers After Queries
[Solution] 985. Sum of Even Numbers After Queries