985. Sum of Even Numbers After Queries
https://leetcode.com/problems/sum-of-even-numbers-after-queries/
Python
class Solution:
def sumEvenAfterQueries(self, nums: List[int], queries: List[List[int]]) -> List[int]:
total = sum([num for num in nums if num % 2 == 0])
ans = []
for value, index in queries:
if nums[index] % 2 == 0:
total -= nums[index]
nums[index] = nums[index] + value
if nums[index] % 2 == 0:
total += nums[index]
ans.append(total)
return ans