Minimum Number of Operations to Make Array Continuous LeetCode solution in Java

1
class Solution {
2
public int minOperations(int[] nums) {
3
TreeSet<Integer> set = new TreeSet<>();
4
int threshold = nums.length - 1;
5
int max = 0;
6
Arrays.sort(nums);
7
for (int num : nums) {
8
while (!set.isEmpty() && num - set.first() > threshold) {
9
set.remove(set.first());
10
}
11
set.add(num);
12
max = Math.max(max, set.size());
13
}
14
return nums.length - max;
15
}
16
}

0

WPM •0 •0

100%

ACC •0 •0

0s

TIME •0