AI 그게 뭔데
끄적끄적 개발일지
AI 그게 뭔데
전체 방문자
오늘
어제
  • 분류 전체보기 (342)
    • 논문 (5)
    • DL(Deep-Learning) (34)
      • 개념 (14)
      • Python 기초 (14)
      • Tensorflow (6)
      • Pytorch (0)
    • NLP (10)
    • OpenCV (53)
    • DevOps (10)
      • AWS (2)
      • Docker & Kubernetes (4)
      • Spark (3)
      • SQL (1)
    • MacOS (1)
    • React-Native (2)
    • BI (3)
      • GA(Google Analytics) (3)
      • Tableau (0)
    • 알고리즘 (221)
      • 백준 (76)
      • 프로그래머스 (108)
      • 기타 알고리즘 (37)

인기 글

태그

  • Python
  • 백준
  • 알고리즘
  • OpenCV
  • 이코테
  • 프로그래머스
  • level1
  • 파이썬
  • LEVEL2
  • 연습문제

최근 글

hELLO · Designed By 정상우.
AI 그게 뭔데

끄적끄적 개발일지

[LeetCode] Merge Sorted Array (Python)
알고리즘/기타 알고리즘

[LeetCode] Merge Sorted Array (Python)

2022. 5. 22. 13:23
 

Explore - LeetCode

LeetCode Explore is the best place for everyone to start practicing and learning on LeetCode. No matter if you are a beginner or a master, there are always new topics waiting for you to explore.

leetcode.com

 

 

Problem

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-decreasing order.

 

The final sorted array should not be returned by the function, but instead be stored inside the array nums1.

To accommodate this, nums1 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.

 

 

 

solution

class Solution:
    def merge(self, nums1: List[int], m: int, nums2: List[int], n: int) -> None:
        merge_sort = sorted(nums1[:m] + nums2[:n])
        for i in range(n+m):
            nums1[i] = merge_sort[i]

 

class Solution:
    def merge(self, nums1: List[int], m: int, nums2: List[int], n: int) -> None:

        nums1[m:]=nums2
        nums1.sort()

 

'알고리즘 > 기타 알고리즘' 카테고리의 다른 글

[LeetCode] Duplicate Zeros (Python)  (0) 2022.05.16
[LeetCode] Squares of a Sorted Array (Python)  (0) 2022.05.16
[LeetCode] Find Numbers with Even Number of Digits (Python)  (0) 2022.05.16
[LeetCode] Max Consecutive Ones (Python)  (0) 2022.05.16
[이것이 코딩 테스트다 with Python] 고정점 찾기 : 이진탐색  (0) 2022.01.24
    AI 그게 뭔데
    AI 그게 뭔데
    공부와 개발 그리고 AI가 약간 첨가된 흔적 남기기

    티스토리툴바