Leetcode 985. Sum of Even Numbers After Queries
Posted 周洋的Blog
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Leetcode 985. Sum of Even Numbers After Queries相关的知识,希望对你有一定的参考价值。
简单题,按照它给的说法计算就行.
class Solution: def sumEvenAfterQueries(self, A: List[int], queries: List[List[int]]) -> List[int]: s = sum(x for x in A if x % 2 == 0) ans = [] for v, i in queries: new = A[i] + v s += new if new % 2 == 0 else 0 s -= A[i] if A[i] % 2 == 0 else 0 ans.append(s) A[i] = new return ans
以上是关于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