알고리즘/leetcode
[LeetCode][JavaScript] 88. Merge Sorted Array
CooNiHong
2021. 7. 29. 15:17
[LeetCode][JavaScript] 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
[직접 푼 코드]
var merge = function (nums1, m, nums2, n) {
nums1.splice(m, n, ...nums2);
nums1.sort((a, b) => a - b);
return nums1;
};
[문제 풀이]
1. nums1의 3번째 위치부터 3개를 지우고 nums2를 넣어줍니다. (splice 메서드)
2. 오름차순으로 정렬합니다. (sort 메서드)
p.s 어떻게 설명해야 할지 몰라서 직접적으로 설명했습니다.ㅜ
알고리즘 스터디: https://github.com/ROUTINE-STUDY/Algorithm
GitHub - ROUTINE-STUDY/Algorithm: 초보 알고리즘 스터디 / 누구나 참여 가능
초보 알고리즘 스터디 / 누구나 참여 가능 :runner:. Contribute to ROUTINE-STUDY/Algorithm development by creating an account on GitHub.
github.com
누구나 참여 가능한 알고리즘 스터디입니다.
알고리즘뿐만 아니라 개발을 하면서 겪은 이슈, 이론을 정리하는 Routine-Study를 운영 중입니다.
728x90