Created
May 19, 2021 09:41
-
-
Save vrat28/fd3b22d82b2d2b5f35839722541e6d1d to your computer and use it in GitHub Desktop.
Minimum Moves (LC 462)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def minMoves2(self, nums: List[int]) -> int: | |
median = sorted(nums)[len(nums) // 2] | |
return sum(abs(num - median) for num in nums) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment