본문 바로가기

Algorithm/Sorting

(C++) - LeetCode (easy) 88. Merge Sorted Array

반응형

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

 

Merge Sorted Array - LeetCode

Level up your coding skills and quickly land a job. This is the best place to expand your knowledge and get prepared for your next interview.

leetcode.com

간단 정렬 문제였습니다.

📕 풀이방법

📔 입력 및 초기화

nums1과 nums2를 하나로 먼저 합쳐줍니다.

📔 풀이과정

반환값이 없으므로 단순 오름차순으로 nums1을 정렬해주면 됩니다.


📕 Code

📔 C++

class Solution {
public:
    void merge(vector<int>& nums1, int m, vector<int>& nums2, int n) {
        for(int i = 0; i < n; i++){
            nums1[m+i] = nums2[i];
        }
        sort(nums1.begin(), nums1.end());
    }
};

*더 나은 내용을 위한 지적, 조언은 언제나 환영합니다.