LC 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
.)
Return the answer to all queries. Your answer
array should have answer[i]
as the answer to the i
-th query.
class Solution {
public:
vector<int> sumEvenAfterQueries(vector<int>& A, vector<vector<int>>& queries) {
int initval = ;
vector<int> ret;
for(int v : A) {
if(v % == ) initval += v;
}
for(auto v : queries) {
int before = A[v[]];
A[v[]] += v[];
if(before % == ) initval -= before;
if(A[v[]] % == ) initval += A[v[]];
ret.push_back(initval);
}
return ret;
}
};
LC 985. Sum of Even Numbers After Queries的更多相关文章
- 【LEETCODE】47、985. Sum of Even Numbers After Queries
package y2019.Algorithm.array; /** * @ProjectName: cutter-point * @Package: y2019.Algorithm.array * ...
- 【Leetcode_easy】985. Sum of Even Numbers After Queries
problem 985. Sum of Even Numbers After Queries class Solution { public: vector<int> sumEvenAft ...
- [Solution] 985. Sum of Even Numbers After Queries
Difficulty: Easy Question We have an array A of integers, and an array queries of queries. For the i ...
- 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] ...
- #Leetcode# 985. Sum of Even Numbers After Queries
https://leetcode.com/problems/sum-of-even-numbers-after-queries/ We have an array A of integers, and ...
- LeetCode 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 = queri ...
- 【leetcode】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 = quer ...
- 【LeetCode】985. Sum of Even Numbers After Queries 解题报告(C++)
作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 暴力 找规律 日期 题目地址:https://lee ...
- LeetCode.985-查询后偶数的总和(Sum of Even Numbers After Queries)
这是悦乐书的第370次更新,第398篇原创 01 看题和准备 今天介绍的是LeetCode算法题中Easy级别的第232题(顺位题号是985).有一个整数数组A和一个查询数组queries. 对于第i ...
随机推荐
- nginx增加新模块
以gunzip这个模块为例,讲述一下,在nginx中如何安装新的模块 1.首先查看nginx已经安装了哪些模块. nginx –V 2.发现没有gunzip模块,安装 进入nginx的安装目录中,不是 ...
- 线段树lazy模板 luogu3372
线段树写得很少,这么基本的算法还是要会的…… #include<bits/stdc++.h> using namespace std; inline long long read() { ...
- excel单元格数据与文本框数据同步
Private Sub Worksheet_SelectionChange(ByVal Target As Range) ActiveSheet.Shapes().TextFrame2.TextRan ...
- springboot 使用 @data 插件,减少代码量
一.idea 安装 lombok 插件 二.重启 idea 三.添加依赖 <dependency> <groupId>org.projectlombok</groupId ...
- idou老师教你学Istio 20 : Istio全景监控与拓扑
根据Istio官方报告,Observe(可观察性)为其重要特性.Istio提供非侵入式的自动监控,记录应用内所有的服务. 我们知道在Istio的架构中,Mixer是管理和收集遥测信息的组件.每一次当请 ...
- 登录授权、TCP/IP、HTTPS
今天继续纯理论的东东,比较枯燥,但是又很重要,坚持.. 登录和授权 登录和授权的区别: 登录:身份认证,即确认「你是你」的过程. 授权:由身份或持有的令牌确认享有某些权限(例如获取用户信息).登录过程 ...
- Spring框架集成FreeMarker
一.Spring in Action (转自:http://blog.163.com/zhang-_-jie/blog/static/16178437820105821120822/ ) FreeMa ...
- 多git项目中账户的管理
每个项目配置用户名: git config user.name "your_name" git config user.email "your_email" 如 ...
- Codeforces Round #542 [Alex Lopashev Thanks-Round] (Div. 1) 题解
A. Toy Train 时间限制:2 seconds 内存限制:256 megabytes 题意 有编号111~n(n≤5000)n(n\le 5000)n(n≤5000)的车站顺时针呈环排列,有m ...
- 为什么添加了@Aspect 还要加@Component(转)
官方文档中有写: You may register aspect classes as regular beans in your Spring XML configuration, or autod ...