Skip to content

Commit

Permalink
[프로그래머스] 재밌는 레이싱 경기장
Browse files Browse the repository at this point in the history
  • Loading branch information
ehdgua01 committed Sep 1, 2024
1 parent c10564d commit 3c7628d
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions coding_test/programmers/racing_stadium.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
def solution(heights):
heights.sort()
if len(heights) % 2:
max_height = heights.pop()
right = len(heights) // 2
result = [
*(heights[right + i] - heights[i] for i in range(len(heights) // 2)),
max_height - heights[right],
]
result.sort()
return result[1]
else:
right = len(heights) // 2
return min(heights[right + i] - heights[i] for i in range(len(heights) // 2))

0 comments on commit 3c7628d

Please sign in to comment.