728x90
1. Problem: py.checkio.org/en/mission/median/
2. My solution:
def checkio(data: List[int]) -> [int, float]:
dummy = sorted(data)
len_list = len(dummy)
# For odd elements
if len_list % 2 == 1: return dummy[len_list // 2]
# For even elements
else: return (dummy[len_list // 2 - 1] + dummy[len_list // 2]) / 2
728x90
'프로그래밍 문제 > [Python] CheckIO' 카테고리의 다른 글
[Check-IO] Absolute Sorting (0) | 2021.11.14 |
---|---|
[Check-IO] Frequency Sorting (0) | 2021.04.18 |
[CheckIO] Remove All After (0) | 2021.03.22 |
[Check-IO] Lightbulb Intro (0) | 2021.03.17 |
[CheckIO] Majority (0) | 2021.03.11 |
댓글