[Python-Leetcode] 4. Median of Two Sorted Arrays (difficulty : Hard - ☆☆☆)
문제 설명 Given two sorted arrays nums1 and nums2 of size m and n respectively, return the median of the two sorted arrays. The overall run time complexity should be O(log (m+n)). Example 1: Input: nums1 = [1,3], nums2 = [2] Output: 2.00000 Explanation: merged array = [1,2,3] and median is 2. Example 2: Input: nums1 = [1,2], nums2 = [3,4] Output: 2.50000 Explanation: merged array = [1,2,3,4] and med..
2022. 4. 27.
Python - Sorted (정렬, key 2개) 오름차순 / 내림차순
파이썬, Sorted 정렬 (Key 2개) dic1 = {'A':[(0, 1), (5, 1), (5, 3), (9, 2), (6, 2), (6, 1)]} dic1 {'A': [(0, 1), (5, 1), (5, 3), (9, 2), (6, 2), (6, 1)]} dic1['A']를 sorting할 때, 앞의 숫자는 증가하는 방향(오름차순) / 뒤의 숫자는 내림차순하도록 하려면 sorted(dic1['A'], key=lambda x:(x[0], -x[1])) [(0, 1), (5, 3), (5, 1), (6, 2), (6, 1), (9, 2)] sorted에서, key는 어떤 것을 기준으로 sort를 할 것인지를 정하는 것입니다. x[0]은 앞의 숫자를 기준으로 오름차순이며, -x[1]은 뒤의 숫자를 기준..
2021. 8. 9.