Problem Solving

94. Merge Sorted Array

굥깡 2023. 1. 19. 05:35
728x90

https://leetcode.com/problems/merge-sorted-array/description/

 

Merge Sorted Array - LeetCode

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. Merge nums1 and nums2 into a single array sorted in non-de

leetcode.com

두 개의 array를 합치는 문제, array nums1을 수정하는 식으로 풀어야 함

class Solution:
    def merge(self, nums1: List[int], m: int, nums2: List[int], n: int) -> None:
        """
        Do not return anything, modify nums1 in-place instead.
        """
        nums1[m:] = nums2
        nums1.sort()

문제의 의도를 잘 모르겠지만 쉽게 풀었음