Reduction Operations to Make the Array Elements Equal - LeetCode 1887 - Python

preview_player
Показать описание
Solution, explanation, and complexity analysis for LeetCode 1887 in Python.

Problem Description:

Code:
Рекомендации по теме
Комментарии
Автор

this was my code in java that worked:

public int reductionOperations(int[] nums) {
int maxNum = 0;
Arrays.sort(nums);
HashSet<Integer> a = new HashSet<>();
for(Integer x: nums){
a.add(x);
}
for(int i =nums.length-1; i>=0; i--){
a.remove(nums[i]);
maxNum+=(a.size());
}

return maxNum;
}
I would put all the items in and keep removing the max one while iterating through the original array and adding the size of the hashset

rheemk
visit shbcf.ru