码迷,mamicode.com
首页 > 其他好文 > 详细

leetcode985

时间:2019-02-03 17:57:33      阅读:169      评论:0      收藏:0      [点我收藏+]

标签:list   lse   port   lis   ret   dex   bsp   app   tco   

import sys

class Solution:
    def sumEvenAfterQueries(self, A: List[int], queries: List[List[int]]) -> List[int]:
        result = list()
        len0 = len(A)
        len1 = len(queries)
        len2 = len(queries[0])
        sums = sys.maxsize

        for i in range(len1):
            #print(i)
            val = queries[i][0]
            index = queries[i][1]
            if sums == sys.maxsize:
                A[index] += val
                sums = 0
                for j in range(len0):
                    cur0 = A[j]
                    if cur0 % 2 == 0:
                        sums += cur0
            else:
                cur = A[index] + val
                if cur % 2 == 0:
                    if A[index] % 2 == 0:
                        sums += val
                    else:
                        sums += cur
                    A[index] = cur
                else:
                    if A[index] % 2 == 0:
                        sums -= A[index]
                    else:
                        sums += 0
                    A[index] = cur
            result.append(sums)
            
        return result

 

leetcode985

标签:list   lse   port   lis   ret   dex   bsp   app   tco   

原文地址:https://www.cnblogs.com/asenyang/p/10350640.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!