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:
Matej Focko 2023-11-19 19:38:04 +01:00
parent 5a1f18c31e
commit 43e0ba224d
Signed by: mfocko
GPG key ID: 7C47D46246790496

View file

@ -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;
}
}