Skip to content

Instantly share code, notes, and snippets.

@vrat28
Created May 19, 2021 09:41
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save vrat28/fd3b22d82b2d2b5f35839722541e6d1d to your computer and use it in GitHub Desktop.
Save vrat28/fd3b22d82b2d2b5f35839722541e6d1d to your computer and use it in GitHub Desktop.
Minimum Moves (LC 462)
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