Created
July 2, 2021 14:12
-
-
Save dongwooklee96/8965b694419eefaffb5d15fa757bc30d to your computer and use it in GitHub Desktop.
problem 1.6
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| """ | |
| 문제 1.6: 주어진 두 배열 (nums1, nums2)을 정렬을 유지하면서 | |
| 병합을 해보자. | |
| """ | |
| from typing import List | |
| def merge(nums1: List[int], m: int, nums2: List[int], n: int) -> None: | |
| i = m - 1 | |
| j = n - 1 | |
| k = m + n - 1 | |
| while i >= 0 and j >= 0: | |
| if nums1[i] < nums2[j]: | |
| nums1[k] = nums2[j] | |
| j -= 1 | |
| else: | |
| nums1[k] = nums1[i] | |
| i -= 1 | |
| k -= 1 | |
| while j >= 0: | |
| nums1[k] = nums2[j] | |
| k -= 1 | |
| j -= 1 | |
| return nums1 | |
| if __name__ == "__main__": | |
| nums1 = list(map(int, input().split())) | |
| nums2 = list(map(int, input().split())) | |
| print(merge(nums1, len(nums1), nums2, len(nums2))) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment