| 일 | 월 | 화 | 수 | 목 | 금 | 토 |
|---|---|---|---|---|---|---|
| 1 | 2 | 3 | 4 | 5 | 6 | 7 |
| 8 | 9 | 10 | 11 | 12 | 13 | 14 |
| 15 | 16 | 17 | 18 | 19 | 20 | 21 |
| 22 | 23 | 24 | 25 | 26 | 27 | 28 |
Tags
- 문제해결
- Certbot/dns-route53
- C++
- leetcode
- 3D PRINTING
- GitLab
- on-prem
- swift
- 리트코드
- 2022
- ingress-nginx
- 알고리즘
- Qualification Round
- MySQL
- Code Jam
- LEVEL 2
- Algorithm
- K8S
- Kubernetes
- 프로그래머스
- 하늘과 바람과 별과 시
- 하늘과 바람과 별과 詩
- hackerrank
- ProblemSolving
- 파이썬
- Code Jam 2022
- 해커랭크
- Python
- 코딩테스트
Archives
- Today
- Total
공대생의 비망록
[LeetCode][Easy] Merge Sorted Array Python 풀이 본문
Programming Language/Python
[LeetCode][Easy] Merge Sorted Array Python 풀이
myungsup1250 2026. 2. 7. 23:27class Solution:
def merge(self, nums1: List[int], m: int, nums2: List[int], n: int) -> None:
"""
Do not return anything, modify nums1 in-place instead.
"""
if n == 0:
return
if m == 0:
# nums1 = nums2 # This will not meet the in-place requirement
for i in range(n): # To meet the in-place requirement
nums1[i] = nums2[i]
return
i = m - 1; j = n - 1
while i >= 0 and j >= 0:
if nums1[i] > nums2[j]:
nums1[i+j+1] = nums1[i]
i -= 1
else:
nums1[i+j+1] = nums2[j]
j -= 1
while j >= 0:
nums1[j] = nums2[j]
j -= 1
return'Programming Language > Python' 카테고리의 다른 글
| [LeetCode][Easy] Missing Number Python 풀이 (0) | 2026.02.08 |
|---|---|
| [LeetCode][Easy] Move Zeroes Python 풀이 (0) | 2026.02.08 |
| [LeetCode][Easy] Contains Duplicate 문제 Python 풀이 (0) | 2026.02.05 |
| [LeetCode][Easy] Two Sum 문제 Python 풀이 (0) | 2026.02.05 |
Comments
