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 ...
随机推荐
- 【Distributed】分布式锁
一.概述 1.1 分布式解决的核心思路 1.2 分布式锁一般有三种实现方式 二.基于Redis的分布式锁 2.1 使用常用命令 2.2 实现思路 2.3 核心代码 Maven依赖信息 LockRedi ...
- myeclipse 添加反编译插件
文件下载地址: 链接: https://pan.baidu.com/s/1th2goaA2aS45kO84dX1Bdg 密码: g1fu 先关闭myeclipse1.下载jad1.5.8g 下载后解压 ...
- 【2018-01-26】SqlServer 检查死锁和阻塞
利用sys.sysprocesses SQL进程检查是否出现死锁和阻塞 Sys.SysProcesses 系统表是一个很重要的系统视图,主要用来定位与解决Sql Server的阻塞和死锁 select ...
- awk 内置函数的使用
转自:http://gdcsy.blog.163.com/blog/static/12734360920130241521280/ 一.split 初始化和类型强制 awk的内建函数sp ...
- Kinect for Windows SDK开发入门(七):骨骼追踪基础 下
http://www.cnblogs.com/yangecnu/archive/2012/04/09/KinectSDK_Skeleton_Tracking_Part2.html 上一篇文章用在UI界 ...
- alibaba 用360的evpp -》个别项目
- vimrc config and NERDTree
nmap <C-N> :tabnext<CR> 下载和配置 NERDTree插件的官方地址如下,可以从这里获取最新的版本 https://github.com/scrooloo ...
- Python+request 获取响应(elapsed)和响应时间(timeout)《七》
requests发请求时,接口的响应时间,也是我们需要关注的一个点,如果响应时间太长,也是不合理的.如果服务端没及时响应,也不能一直等着,可以设置一个timeout超时的时间 具体的实现如下: 超时( ...
- Web UI开发神器—Kendo UI for jQuery数据管理网格编辑操作
Kendo UI for jQuery最新试用版下载 Kendo UI目前最新提供Kendo UI for jQuery.Kendo UI for Angular.Kendo UI Support f ...
- Springboot AOP写操作日志 GET POST
pom.xml <dependency> <groupId>org.springframework.boot</groupId> <artifactId> ...