Notice
Recent Posts
Recent Comments
Link
| 일 | 월 | 화 | 수 | 목 | 금 | 토 |
|---|---|---|---|---|---|---|
| 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 | 29 | 30 | 31 |
Tags
- 파이썬알고리즘
- 파이썬 프로그래머스
- 알고리즘풀이
- 잇츠디모
- python Leetcode
- 파이썬알고리즘풀기
- 릿코드풀기
- 파이썬 알고리즘 풀기
- leetcode풀이
- binary search
- 코틀린기초
- 릿코드 파이썬
- python sorted
- 알고리즘풀기
- leetcode 풀기
- 릿코드 풀기
- 릿코드풀이
- 파이썬 릿코드
- 파이썬릿코드
- 파이썬 알고리즘
- 릿코드
- python zip_longest
- python 알고리즘
- leetcode풀기
- LeetCode
- python priority queue
- 파이썬릿코드풀기
- python xor
- 상가수익률계산기
- python 릿코드
Archives
- Today
- Total
소프트웨어에 대한 모든 것
462. Minimum Moves to Equal Array Elements II 본문
반응형
https://leetcode.com/problems/minimum-moves-to-equal-array-elements-ii/
Minimum Moves to Equal Array Elements II - 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
462. Minimum Moves to Equal Array Elements II
문제)

솔루션1)
1) 오름차순 정렬
2) 중앙값 검색
3) 중앙값을 기준으로 각 elements에 대해서 move 계산
class Solution:
def minMoves2(self, nums: List[int]) -> int:
nums.sort()
median_num = nums[len(nums)//2]
return sum(abs(median_num - n) for n in nums)
반응형
'알고리즘 > LeetCode' 카테고리의 다른 글
| 1026. Maximum Difference Between Node and Ancestor (0) | 2022.12.09 |
|---|---|
| 6. Zigzag Conversion (0) | 2022.12.07 |
| 5. Longest Palindromic Substring (0) | 2022.05.24 |
| LeetCode 풀기 - 79. Word Search (0) | 2022.03.30 |
| LeetCode 풀기 - 101. Symmetric Tree (0) | 2022.03.26 |
Comments