본문 바로가기
알고리즘

[알고리즘 & 영어공부]LeetCode 88. Merge Sorted Array

by 내가 진짜 유일한 2024. 11. 21.

English content

You are given two integer arrays num1 and num2, sorted in non-decreasing order, and two integers m and n, representing the number of elements in num1 and num2 respectively.

Merge num1 and num2 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 num1. To accommodate this, num1 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.

내가 해석한 내용

num1, num2 두 정수형 배열을 주어지고, non-decreasing 순서로 정렬된다.

그리고 두 정수 m, n은 representing한 요소의 수인 num1, num2는 respectively 하다.

Merge num1, num2은 한 배열에 decreasing 순서로 정렬된다

마지막 정렬한 배열은 함수로 return 되어서는 안된다, 하지만 대신에 num1 배열안에는 정렬한다.

이것을 To accommodate, num1 길이는 m+n을 갖고, 첫번째 요소 m은 denote 그 요소들은 무시해야한다.

num2 배열은 n의 길이는 갖는다.

 

영어 단어 영어 단어 해석 단어가 있는 문장
non-decreasing 감소하지 않는 You are given two integer arrays num1 and num2, sorted in non-decreasing order
respectively 각기 representing the number of elements in num1 and num2 respectively
To acoommodate 수용하기 위해 To accommodate this, num1 has a length of m+n
denote 나타나다, 표시하다, 상징하다 where the first m elements denote the elements that should be merged
representing 대표하는 representing the number of elements in num1 and num2 respectively

모르는 단어 알고 난 후, 해석

num1, num2 두 정수형 배열이 주어지고, 감소하지 않는 순서로 정렬되어 있다. 그리고, 두 정수 m, n은 num1과 num2 각각 요소의 개수를 대표하는 수 이다.

하나의 배열에 감소하지 않은 순서로 정렬해서 num1, num2 를 병합해라.

마지막 정렬된 배열에는 함수로 인해 반환되면 안되지만, 대신에 num1 안에 저장된다.

이를 수용하기 위해, num1는 m+n의 길이를 갖고, 첫 m개 요소가 나타내는 요소들은 병합되어야한다.

그리고 마지막 n개의 요소들은 0으로 설정되어 있고, 무시되어야 한다

num2는 n의 길이를 갖는다.

번역기로 해석한 내용

두 개의 정수 배열 num1과 num2가 비감소 순서로 정렬되어 있고, 두 개의 정수 m과 n이 각각 num1과 num2의 요소 수를 나타냅니다.

num1과 num2를 비감소 순서로 정렬된 단일 배열로 병합합니다.

최종 정렬된 배열은 함수에서 반환되지 않고 대신 배열 num1 내부에 저장되어야 합니다.

이를 수용하기 위해 num1은 m+n의 길이를 가지며,

처음 m개의 요소는 병합되어야 하는 요소를 나타내고 마지막 n개의 요소는 0으로 설정되어 무시되어야 합니다. nums2의 길이는 n입니다.

class Solution(object):
    def merge(self, nums1, m, nums2, n):
        nums1[m:] = nums2
        nums1.sort()