Skip to content

Commit 4633fae

Browse files
authored
Merge pull request #1153 from ivan1016017/january15
adding merge sorted arrays
2 parents e430747 + 93adb22 commit 4633fae

File tree

2 files changed

+26
-0
lines changed

2 files changed

+26
-0
lines changed
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
from typing import List, Union, Collection, Mapping, Optional
2+
from abc import ABC, abstractmethod
3+
4+
class Solution:
5+
def merge(self,
6+
nums1: List[int],
7+
m: int, nums2: List[int],
8+
n: int) -> None:
9+
10+
nums1[m: m+n] = nums2
11+
12+
nums1.sort()
13+
14+
return nums1
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import unittest
2+
from src.my_project.interviews.top_150_questions_round_13\
3+
.merge_sorted_array import Solution
4+
5+
class MergeSortedArrayTestCase(unittest.TestCase):
6+
7+
def test_merge_sorted_array(self):
8+
solution = Solution()
9+
output = solution.merge(nums1=[1,2,3,0,0,0], m=3, nums2=[2,5,6], n=3)
10+
target = [1,2,2,3,5,6]
11+
for k, v in enumerate(target):
12+
self.assertEqual(output[k], v)

0 commit comments

Comments
 (0)