본문 바로가기
python-algorithm

leetcode 462. Minimum Moves to Equal Array Elements II

by 무적김두칠 2022. 6. 30.

1
2
3
4
5
6
7
8
from statistics import median
class Solution:
    def minMoves2(self, nums: List[int]) -> int:
        med=median(nums)
        ans=0
        for i in nums :
            ans+=abs(med-i)
        return int(ans)
cs
반응형

'python-algorithm' 카테고리의 다른 글

leetcode 128. Longest Consecutive Sequence  (0) 2022.07.06
leetcode 509. Fibonacci Number  (0) 2022.07.06
백준 2756 다트  (0) 2022.06.17
백준 14647 준오는 조류혐오야!!  (0) 2022.06.16
codeforces 509A - Maximum in Table  (0) 2022.06.13

댓글