problems(java): add “1887. Reduction Operations to Make the Array Elements Equal”
Signed-off-by: Matej Focko <me@mfocko.xyz>
This commit is contained in:
parent
5a1f18c31e
commit
43e0ba224d
1 changed files with 15 additions and 0 deletions
|
@ -0,0 +1,15 @@
|
||||||
|
class Solution {
|
||||||
|
public int reductionOperations(int[] nums) {
|
||||||
|
Arrays.sort(nums);
|
||||||
|
|
||||||
|
int counter = 0;
|
||||||
|
|
||||||
|
for (int i = nums.length - 1; i > 0; --i) {
|
||||||
|
if (nums[i - 1] != nums[i]) {
|
||||||
|
counter += nums.length - i;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return counter;
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in a new issue