国产精品天干天干,亚洲毛片在线,日韩gay小鲜肉啪啪18禁,女同Gay自慰喷水

歡迎光臨散文網(wǎng) 會員登陸 & 注冊

LeetCode 2363. Merge Similar Items

2023-02-20 14:47 作者:您是打尖兒還是住店呢  | 我要投稿

You are given two 2D integer arrays,?items1?and?items2, representing two sets of items. Each array?items?has the following properties:

  • items[i] = [valuei, weighti]?where?valuei?represents the?value?and?weighti?represents the?weight?of the?ith?item.

  • The value of each item in?items?is?unique.

Return?a 2D integer array?ret?where?ret[i] = [valuei, weighti],?with?weighti?being the?sum of weights?of all items with value?valuei.

Note:?ret?should be returned in?ascending?order by value.

?

Example 1:

Input: items1 = [[1,1],[4,5],[3,8]], items2 = [[3,1],[1,5]]Output: [[1,6],[3,9],[4,5]]Explanation: The item with value = 1 occurs in items1 with weight = 1 and in items2 with weight = 5, total weight = 1 + 5 = 6. The item with value = 3 occurs in items1 with weight = 8 and in items2 with weight = 1, total weight = 8 + 1 = 9. The item with value = 4 occurs in items1 with weight = 5, total weight = 5. ? Therefore, we return [[1,6],[3,9],[4,5]].

Example 2:

Input: items1 = [[1,1],[3,2],[2,3]], items2 = [[2,1],[3,2],[1,3]]Output: [[1,4],[2,4],[3,4]]Explanation: The item with value = 1 occurs in items1 with weight = 1 and in items2 with weight = 3, total weight = 1 + 3 = 4. The item with value = 2 occurs in items1 with weight = 3 and in items2 with weight = 1, total weight = 3 + 1 = 4. The item with value = 3 occurs in items1 with weight = 2 and in items2 with weight = 2, total weight = 2 + 2 = 4. Therefore, we return [[1,4],[2,4],[3,4]].

Example 3:

Input: items1 = [[1,3],[2,2]], items2 = [[7,1],[2,2],[1,4]]Output: [[1,7],[2,4],[7,1]]Explanation:The item with value = 1 occurs in items1 with weight = 3 and in items2 with weight = 4, total weight = 3 + 4 = 7. The item with value = 2 occurs in items1 with weight = 2 and in items2 with weight = 2, total weight = 2 + 2 = 4. The item with value = 7 occurs in items2 with weight = 1, total weight = 1. Therefore, we return [[1,7],[2,4],[7,1]].

?

Constraints:

  • 1 <= items1.length, items2.length <= 1000

  • items1[i].length == items2[i].length == 2

  • 1 <= valuei, weighti?<= 1000

  • Each?valuei?in?items1?is?unique.

  • Each?valuei?in?items2?is?unique.




跟前面2天合并的題目基本一樣,只是那個是數(shù)組,這個是隊列了。


Runtime:?8 ms, faster than?70.33%?of?Java?online submissions for?Merge Similar Items.

Memory Usage:?43.1 MB, less than?56.96%?of?Java?online submissions for?Merge Similar Items.


LeetCode 2363. Merge Similar Items的評論 (共 條)

分享到微博請遵守國家法律
乌兰浩特市| 潢川县| 庆安县| 清水河县| 松溪县| 建阳市| 嘉鱼县| 博白县| 邹平县| 大城县| 黑水县| 抚州市| 奇台县| 潼南县| 友谊县| 永仁县| 民县| 乐业县| 囊谦县| 神农架林区| 陵水| 威海市| 秦安县| 宁国市| 乃东县| 阿拉善盟| 平乐县| 浮山县| 信阳市| 公安县| 南华县| 包头市| 安阳县| 南陵县| 普兰店市| 澄城县| 收藏| 平陆县| 平塘县| 丹阳市| 谢通门县|