Skip to content

Commit 16bc40b

Browse files
committed
Mar 2
1 parent 4adfb17 commit 16bc40b

File tree

2 files changed

+34
-2
lines changed

2 files changed

+34
-2
lines changed
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
class Solution:
2+
def mergeArrays(self, nums1: list[list[int]], nums2: list[list[int]]) -> list[list[int]]:
3+
result = []
4+
ptr1, ptr2 = 0, 0
5+
while ptr1 < len(nums1) and ptr2 < len(nums2):
6+
if nums1[ptr1][0] == nums2[ptr2][0]:
7+
result.append([nums1[ptr1][0], nums1[ptr1][1]+nums2[ptr2][1]])
8+
ptr1 += 1
9+
ptr2 += 1
10+
elif nums1[ptr1][0] > nums2[ptr2][0]:
11+
result.append(nums2[ptr2])
12+
ptr2 += 1
13+
else:
14+
result.append(nums1[ptr1])
15+
ptr1 += 1
16+
result.extend(nums1[ptr1:])
17+
result.extend(nums2[ptr2:])
18+
return result
19+
20+
21+
def main():
22+
nums1 = [[1, 2], [2, 3], [4, 5]]
23+
nums2 = [[1, 4], [3, 2], [4, 1]]
24+
assert Solution().mergeArrays(nums1, nums2) == [[1, 6], [2, 3], [3, 2], [4, 6]]
25+
26+
nums1 = [[2, 4], [3, 6], [5, 5]]
27+
nums2 = [[1, 3], [4, 3]]
28+
assert Solution().mergeArrays(nums1, nums2) == [[1, 3], [2, 4], [3, 6], [4, 3], [5, 5]]
29+
30+
31+
if __name__ == '__main__':
32+
main()

2025-03-March-LeetCoding-Challenge/README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
| Day | Problem | Level | Status |
66
| --- | --- | --- | --- |
77
| March 01 | [2460. Apply Operations to an Array](https://leetcode.com/problems/apply-operations-to-an-array/) | Easy | Solved |
8-
| March 02 | []() | | |
8+
| March 02 | [2570. Merge Two 2D Arrays by Summing Values](https://leetcode.com/problems/merge-two-2d-arrays-by-summing-values/) | Easy | Solved |
99
| March 03 | []() | | |
1010
| March 04 | []() | | |
1111
| March 05 | []() | | |
@@ -40,6 +40,6 @@
4040
## Summary
4141
| Level | Problems | Solved | Unsolved |
4242
| --- | --- | --- | --- |
43-
| Easy | 1 | 1 | 0 |
43+
| Easy | 2 | 2 | 0 |
4444
| Medium | 0 | 0 | 0 |
4545
| Hard | 0 | 0 | 0 |

0 commit comments

Comments
 (0)