Very easy O(n) c++ solution


  • 0
    H

    class Solution {
    public:
    int minMoves(vector<int>& nums) {
    int min=nums[0];
    for(int i=1;i<nums.size();i++)
    {
    if(nums[i]<min) min=nums[i];
    }
    int moves=0;
    for (int i=0;i<nums.size();i++)
    {
    moves+=nums[i]-min;
    }
    return moves;

    }
    

    };


Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.