2570. Merge Two 2D Arrays by Summing Values 發表於 2024-02-03 | 分類於 leetcode problemsolution1234567891011121314151617181920212223class Solution {public: vector<vector<int>> mergeArrays(vector<vector<int>>& nums1, vector<vector<int>>& nums2) { int n = nums1.size(), m = nums2.size(); vector<vector<int>> rets; int l=0, r=0; while(l<n && r<m) { if(nums1[l][0]==nums2[r][0] ) { rets.push_back({nums1[l][0], nums1[l][1]+ nums2[r][1] }); l++;r++; } else if(nums1[l][0] <nums2[r][0] ) { rets.push_back(nums1[l++]); } else rets.push_back(nums2[r++]); } while(l<n) rets.push_back(nums1[l++]); while(r<m) rets.push_back(nums2[r++]); return rets; }}; analysis time complexity space complexity