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 ...
随机推荐
- Linux下源码包安装Swoole及基本使用 转
版权声明:本文为博主原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接和本声明. 本文链接:https://blog.csdn.net/msllws/article/details ...
- linux添加地址映射
- 【转】Elastic-Job
https://www.cnblogs.com/yushangzuiyue/p/9655847.html 什么是Elastic-Job Elastic-Job是当当网大牛基于Zookepper,Qua ...
- ubuntu---github下载太慢的解决办法
git clone --recursive https://github.com/tensorflow/tensorflow 下载太慢了,20:05-21:17 才下载了17%,等的太急人了. ** ...
- Jsp与JavaScript区别
有时候会误以为这两个是同一个概念,但其实不是 Jsp全名为Java Server Pages(Java服务器页面),其根本是一个简化的Servlet设计,他实现了在Java当中使用HTML标签.Jsp ...
- Python+request 分模块存放接口,多接口共用参数URL、headers的抽离,添加日志打印等《三》
主要介绍内容如下: 1.分模块存放接口 2.多接口共用参数URL.headers的抽离为配置文件 3.添加日志打印 4.一个py文件运行所有所测的接口 如上介绍内容的作用: 1.分模块存放接口:方便多 ...
- GEF中TreeViewer的叶子节点展开
/** * GEF树叶子节点的展开 * @param items */ private void expand(TreeItem[] items) { for (int i = 0; i < i ...
- shiro框架的UsernamePasswordToken与对应Realm中的AuthenticationToken的一点比较(转)
这里以简单的登陆为例子 控制器对应的登陆方法: @RequestMapping(value = "/login", method = RequestMethod.GET) publ ...
- 爬取淘宝商品数据并保存在excel中
1.re实现 import requests from requests.exceptions import RequestException import re,json import xlwt,x ...
- Mac工具库
1.文件传输工具 CyberDuck 2.解压缩工具 The Unarchiver 3. 录屏工具 LICEcap 4. 命令框工具 Go2Shell / iTerm 5. 提醒事项 OmniFocu ...