Skip to content

Commit 4c2e06a

Browse files
authored
Create 1887_Reduction_Operations_to_Make_the_Array_Elements_Equal.java
1 parent 4e56d8c commit 4c2e06a

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
// id: 1887
2+
// Name: Reduction Operations to Make the Array Elements Equal
3+
// link: https://leetcode.com/problems/reduction-operations-to-make-the-array-elements-equal/
4+
// Difficulty: Medium
5+
6+
class Solution {
7+
public int reductionOperations(int[] nums) {
8+
Arrays.sort(nums);
9+
10+
int result = 0;
11+
12+
int count = 0;
13+
for(int i = 1; i < nums.length; i++) {
14+
if (nums[i] != nums[i-1]) {
15+
count++;
16+
}
17+
result += count;
18+
}
19+
return result;
20+
}
21+
}

0 commit comments

Comments
 (0)