Skip to content

Commit 858c55d

Browse files
authored
Create minimum-moves-to-equal-array-elements.cpp
1 parent 93e4b48 commit 858c55d

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
// Time: O(n)
2+
// Space: O(1)
3+
4+
class Solution {
5+
public:
6+
int minMoves(vector<int>& nums) {
7+
return accumulate(nums.cbegin(), nums.cend(), 0) -
8+
nums.size() * *min_element(nums.cbegin(), nums.cend());
9+
}
10+
};

0 commit comments

Comments
 (0)