Skip to content

Commit 11b48ec

Browse files
author
Danieldu
committed
add 2570 2579
1 parent b6fb231 commit 11b48ec

File tree

2 files changed

+51
-0
lines changed

2 files changed

+51
-0
lines changed
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
/*
2+
* @lc app=leetcode id=2570 lang=cpp
3+
*
4+
* [2570] Merge Two 2D Arrays by Summing Values
5+
*/
6+
7+
// @lc code=start
8+
#include <bits/stdc++.h>
9+
using namespace std;
10+
11+
class Solution {
12+
public:
13+
vector<vector<int>> mergeArrays(vector<vector<int>>& nums1, vector<vector<int>>& nums2) {
14+
map<int, int> mergedMap;
15+
16+
for (const auto& num : nums1) {
17+
mergedMap[num[0]] += num[1];
18+
}
19+
20+
for (const auto& num : nums2) {
21+
mergedMap[num[0]] += num[1];
22+
}
23+
24+
vector<vector<int>> result;
25+
result.reserve(mergedMap.size());
26+
27+
for (const auto& [key, value] : mergedMap) {
28+
result.emplace_back(vector<int>{key, value});
29+
}
30+
31+
return result;
32+
}
33+
};
34+
35+
// @lc code=end
36+
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
/*
2+
* @lc app=leetcode id=2579 lang=cpp
3+
*
4+
* [2579] Count Total Number of Colored Cells
5+
*/
6+
7+
// @lc code=start
8+
class Solution {
9+
public:
10+
long long coloredCells(int n) {
11+
return 2LL * n * n - 2LL * n + 1;
12+
}
13+
};
14+
// @lc code=end
15+

0 commit comments

Comments
 (0)