# Leetcode-Easy 985. Sum of Even Numbers After Queries

## 题目描述

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.)

## 代码实现

class Solution:
def sumEvenAfterQueries(self, A: 'List[int]', queries: 'List[List[int]]') -> 'List[int]':
new_A=[None]*len(A)
even_index=[a if a%2==0 else 0 for a in A]
for i in range(len(A)):
val = queries[i][0]
index = queries[i][1]
A[index]+=val
if A[index]%2==0:
even_index[index]=A[index]
else:
even_index[index]=0
new_A[i]=sum(even_index)
return new_A

|
9月前
|

|
12月前
|

LeetCode - #2 Add Two Numbers

56 0
LeetCode Contest 186 5392. 分割字符串的最大得分 Maximum Score After Splitting a String
LeetCode Contest 186 5392. 分割字符串的最大得分 Maximum Score After Splitting a String
70 0
LeetCode 1380. 矩阵中的幸运数 Lucky Numbers in a Matrix
LeetCode 1380. 矩阵中的幸运数 Lucky Numbers in a Matrix
118 0
LeetCode Contest 178-1365. 有多少小于当前数字的数字 How Many Numbers Are Smaller Than the Current Number
LeetCode Contest 178-1365. 有多少小于当前数字的数字 How Many Numbers Are Smaller Than the Current Number
70 0
LeetCode 5340. 统计有序矩阵中的负数 Count Negative Numbers in a Sorted Matrix
LeetCode 5340. 统计有序矩阵中的负数 Count Negative Numbers in a Sorted Matrix
75 0
LeetCode 357. Count Numbers with Unique Digits

67 0
|

LeetCode 315. Count of Smaller Numbers After Self

77 0
|

53 0
|