Skip to content

Create Solution 0985 [Solution.py] #150

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Feb 13, 2019
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
Create Solution 0985 [Solution.py]
  • Loading branch information
BradyHu committed Feb 13, 2019
commit 01305967e9be949a4b138753773da74f15abb02c
16 changes: 16 additions & 0 deletions solution/0985.Sum of Even Numbers After Queries/Solution.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
class Solution:
def sumEvenAfterQueries(self, A: 'List[int]', queries: 'List[List[int]]') -> 'List[int]':
base = sum(filter(lambda x:x%2==0,A))
ans = []
for val,index in queries:
if A[index]%2==0:
base-=A[index]
A[index]+=val
if A[index]%2==0:
base+=A[index]
else:
A[index]+=val
if A[index]%2==0:
base+=A[index]
ans.append(base)
return ans