Algorithm/문제
[Leetcode] 4. Median of Two Sorted Arrays
Lim Seung Hyun
2022. 6. 10. 08:47
문제 출처
Median of Two Sorted Arrays - 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
문제 이해
- 정렬된 두 개의 리스트를 합쳐 중간값을 구하기
나의 풀이 (Python3)
import statistics
class Solution:
def findMedianSortedArrays(self, nums1: List[int], nums2: List[int]) -> float:
nums1.extend(nums2)
median = statistics.median(nums1)
return median
- 두 리스트를 extend하고 statistics의 median 함수를 사용하였다.
결과
- 나름 런타임은 빠른편인거 같지만 이렇게 푸는 건 아닌 것 같다.
- 두 리스트를 merge 구문은 따로 구현하고 정렬 구현, 중간값 도출 구문도 각각 구현해야 할 것으로 보임
728x90