Skip to content

Commit 4bfc662

Browse files
authored
Create 2009-minimum-number-of-operations-to-make-array-continuous.kt
1 parent 410595a commit 4bfc662

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
class Solution {
2+
fun minOperations(_nums: IntArray): Int {
3+
val length = _nums.size
4+
val nums = _nums.toSet().toIntArray().sorted()
5+
var res = length
6+
var right = 0
7+
8+
for (left in 0 until length) {
9+
while (right < nums.size && nums[right] < nums[left] + length)
10+
right++
11+
res = minOf(res, length - (right - left))
12+
}
13+
14+
return res
15+
}
16+
}

0 commit comments

Comments
 (0)