mirror of
https://gitlab.com/mfocko/LeetCode.git
synced 2024-11-09 15:59:06 +01:00
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