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
Prev Previous commit
Update Solution.py
  • Loading branch information
yanglbme authored Feb 13, 2019
commit 73a50aed599352c3e986bb456463afadf5519bdd
22 changes: 11 additions & 11 deletions solution/0985.Sum of Even Numbers After Queries/Solution.py
Original file line number Diff line number Diff line change
@@ -1,16 +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))
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]
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]
A[index] += val
if A[index] % 2 == 0:
base += A[index]
ans.append(base)
return ans
return ans