"Leetcode simple" question 103th the minimum number of moves makes the array elements equal

Source: Internet
Author: User

Given an array of non-empty integers of length n , find the minimum number of moves that allow all elements of the array to be equal. Each move can increase the n -1 elements by 1.

Example:

Input: [A] output:3 Explanation: only 3 moves are required (note that each move increases the value of two elements): [three-to-one]  = [2,3,3] and [  3,4,3]  = >  [4,4,4]
class Solution:     def minmoves (Self, nums):         """         : Type Nums:list[int]        : rtype:int        """        return sum (nums)-min (nums) *len (Nums)

"Leetcode simple" question 103th the minimum number of moves makes the array elements equal

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.