diff --git a/README.md b/README.md index f0af30ab..45c510c0 100755 --- a/README.md +++ b/README.md @@ -1,12 +1,6 @@ ## Python Snippets [![Build Status](https://travis-ci.org/BrianLusina/Python_Snippets.svg?branch=master)](https://travis-ci.org/BrianLusina/Python_Snippets) -[![codecov](https://codecov.io/gh/BrianLusina/Python_Snippets/branch/master/graph/badge.svg)](https://codecov.io/gh/BrianLusina/Python_Snippets) -[![Codacy Badge](https://api.codacy.com/project/badge/Grade/11cfc8e125c54bdb833fe19ed9ddad72)](https://www.codacy.com/app/BrianLusina/Python_Snippets?utm_source=github.com&utm_medium=referral&utm_content=BrianLusina/Python_Snippets&utm_campaign=Badge_Grade) -[![Codacy Badge](https://api.codacy.com/project/badge/Coverage/11cfc8e125c54bdb833fe19ed9ddad72)](https://www.codacy.com/app/BrianLusina/Python_Snippets?utm_source=github.com&utm_medium=referral&utm_content=BrianLusina/Python_Snippets&utm_campaign=Badge_Coverage) -[![CircleCI](https://circleci.com/gh/BrianLusina/Python_Snippets.svg?style=svg)](https://circleci.com/gh/BrianLusina/Python_Snippets) -[![Dependency Status](https://gemnasium.com/badges/github.com/BrianLusina/Python_Snippets.svg)](https://gemnasium.com/github.com/BrianLusina/Python_Snippets) -[![Dependency Status](https://dependencyci.com/github/BrianLusina/Python_Snippets/badge)](https://dependencyci.com/github/BrianLusina/Python_Snippets) Repository for some of my simple [Python](https://www.python.org/ "Python") functions and snippets. Each directory and/or python package has a readme for more information about the Python program diff --git a/algorithms/two_pointers/__init__.py b/algorithms/two_pointers/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/datastructures/arrays/merge_sorted_arrays/README.md b/algorithms/two_pointers/merge_sorted_arrays/README.md similarity index 66% rename from datastructures/arrays/merge_sorted_arrays/README.md rename to algorithms/two_pointers/merge_sorted_arrays/README.md index 9a15f479..9b08f38a 100644 --- a/datastructures/arrays/merge_sorted_arrays/README.md +++ b/algorithms/two_pointers/merge_sorted_arrays/README.md @@ -1,23 +1,33 @@ # Merge Sorted Array -You are given two integer arrays nums1 and nums2, sorted in non-decreasing order, and two integers m and n, representing the number of elements in nums1 and nums2 respectively. +You are given two integer arrays nums1 and nums2, sorted in non-decreasing order, and two integers m and n, representing +the number of elements in nums1 and nums2 respectively. Merge nums1 and nums2 into a single array sorted in non-decreasing order. -The final sorted array should not be returned by the function, but instead be stored inside the array nums1. To accommodate this, nums1 has a length of m + n, where the first m elements denote the elements that should be merged, and the last n elements are set to 0 and should be ignored. nums2 has a length of n. +The final sorted array should not be returned by the function, but instead be stored inside the array nums1. To +accommodate this, nums1 has a length of m + n, where the first m elements denote the elements that should be merged, and +the last n elements are set to 0 and should be ignored. nums2 has a length of n. +```text Example 1: Input: nums1 = [1,2,3,0,0,0], m = 3, nums2 = [2,5,6], n = 3 Output: [1,2,2,3,5,6] Explanation: The arrays we are merging are [1,2,3] and [2,5,6]. The result of the merge is [1,2,2,3,5,6] with the underlined elements coming from nums1. +``` + +```text Example 2: Input: nums1 = [1], m = 1, nums2 = [], n = 0 Output: [1] Explanation: The arrays we are merging are [1] and []. The result of the merge is [1]. +``` + +```text Example 3: Input: nums1 = [0], m = 0, nums2 = [1], n = 1 @@ -25,3 +35,10 @@ Output: [1] Explanation: The arrays we are merging are [] and [1]. The result of the merge is [1]. Note that because m = 0, there are no elements in nums1. The 0 is only there to ensure the merge result can fit in nums1. +``` + +## Related Topics + +- Array +- Two Pointers +- Sorting diff --git a/datastructures/arrays/merge_sorted_arrays/__init__.py b/algorithms/two_pointers/merge_sorted_arrays/__init__.py similarity index 85% rename from datastructures/arrays/merge_sorted_arrays/__init__.py rename to algorithms/two_pointers/merge_sorted_arrays/__init__.py index d02c3a71..de9c33d3 100644 --- a/datastructures/arrays/merge_sorted_arrays/__init__.py +++ b/algorithms/two_pointers/merge_sorted_arrays/__init__.py @@ -3,7 +3,7 @@ def merge(nums1: List[int], m: int, nums2: List[int], n: int) -> None: """ - Do not return anything, modify nums1 in-place instead. + Does not return anything, modifies nums1 in-place instead. """ while m > 0 and n > 0: if nums1[m - 1] > nums2[n - 1]: diff --git a/tests/datastructures/arrays/test_merge_sorted_arrays.py b/algorithms/two_pointers/merge_sorted_arrays/test_merge_sorted_arrays.py similarity index 93% rename from tests/datastructures/arrays/test_merge_sorted_arrays.py rename to algorithms/two_pointers/merge_sorted_arrays/test_merge_sorted_arrays.py index d3ef7fe0..ae788d70 100644 --- a/tests/datastructures/arrays/test_merge_sorted_arrays.py +++ b/algorithms/two_pointers/merge_sorted_arrays/test_merge_sorted_arrays.py @@ -1,6 +1,6 @@ import unittest -from datastructures.arrays.merge_sorted_arrays import merge +from . import merge class MergeSortedArraysTestCases(unittest.TestCase): @@ -11,7 +11,7 @@ def test_should_return_0_when_empty_array(self): self.assertEqual(nums1, []) def test_set_nums1_to_1_2_2_3_5_6_when_nums1_is_1_2_3_0_0_0_and_m_is_3_and_nums2_is_2_5_6_and_n_is_3( - self, + self, ): """Should set nums1 to [1,2,2,3,5,6] when initially nums1 = [1,2,3,0,0,0], m = 3, nums2 = [2,5,6], n = 3""" nums1 = [1, 2, 3, 0, 0, 0]