2363. Merge Similar Items Easy
1/**
2 * [2363] Merge Similar Items
3 *
4 * You are given two 2D integer arrays, items1 and items2, representing two sets of items. Each array items has the following properties:
5 *
6 * items[i] = [valuei, weighti] where valuei represents the value and weighti represents the weight of the i^th item.
7 * The value of each item in items is unique.
8 *
9 * Return a 2D integer array ret where ret[i] = [valuei, weighti], with weighti being the sum of weights of all items with value valuei.
10 * Note: ret should be returned in ascending order by value.
11 *
12 * Example 1:
13 *
14 * Input: items1 = [[1,1],[4,5],[3,8]], items2 = [[3,1],[1,5]]
15 * Output: [[1,6],[3,9],[4,5]]
16 * Explanation:
17 * The item with value = 1 occurs in items1 with weight = 1 and in items2 with weight = 5, total weight = 1 + 5 = 6.
18 * The item with value = 3 occurs in items1 with weight = 8 and in items2 with weight = 1, total weight = 8 + 1 = 9.
19 * The item with value = 4 occurs in items1 with weight = 5, total weight = 5.
20 * Therefore, we return [[1,6],[3,9],[4,5]].
21 *
22 * Example 2:
23 *
24 * Input: items1 = [[1,1],[3,2],[2,3]], items2 = [[2,1],[3,2],[1,3]]
25 * Output: [[1,4],[2,4],[3,4]]
26 * Explanation:
27 * The item with value = 1 occurs in items1 with weight = 1 and in items2 with weight = 3, total weight = 1 + 3 = 4.
28 * The item with value = 2 occurs in items1 with weight = 3 and in items2 with weight = 1, total weight = 3 + 1 = 4.
29 * The item with value = 3 occurs in items1 with weight = 2 and in items2 with weight = 2, total weight = 2 + 2 = 4.
30 * Therefore, we return [[1,4],[2,4],[3,4]].
31 * Example 3:
32 *
33 * Input: items1 = [[1,3],[2,2]], items2 = [[7,1],[2,2],[1,4]]
34 * Output: [[1,7],[2,4],[7,1]]
35 * Explanation:
36 * The item with value = 1 occurs in items1 with weight = 3 and in items2 with weight = 4, total weight = 3 + 4 = 7.
37 * The item with value = 2 occurs in items1 with weight = 2 and in items2 with weight = 2, total weight = 2 + 2 = 4.
38 * The item with value = 7 occurs in items2 with weight = 1, total weight = 1.
39 * Therefore, we return [[1,7],[2,4],[7,1]].
40 *
41 *
42 * Constraints:
43 *
44 * 1 <= items1.length, items2.length <= 1000
45 * items1[i].length == items2[i].length == 2
46 * 1 <= valuei, weighti <= 1000
47 * Each valuei in items1 is unique.
48 * Each valuei in items2 is unique.
49 *
50 */
51pub struct Solution {}
52
53// problem: https://leetcode.com/problems/merge-similar-items/
54// discuss: https://leetcode.com/problems/merge-similar-items/discuss/?currentPage=1&orderBy=most_votes&query=
55
56// submission codes start here
57
58impl Solution {
59 pub fn merge_similar_items(items1: Vec<Vec<i32>>, items2: Vec<Vec<i32>>) -> Vec<Vec<i32>> {
60 vec![]
61 }
62}
63
64// submission codes end
65
66#[cfg(test)]
67mod tests {
68 use super::*;
69
70 #[test]
71 fn test_2363() {
72 }
73}
74
Back
© 2025 bowen.ge All Rights Reserved.