kt: add «3396. Minimum Number of Operations to Make Elements in Array Distinct»
URL: https://leetcode.com/problems/minimum-number-of-operations-to-make-elements-in-array-distinct/ Signed-off-by: Matej Focko <me@mfocko.xyz>
This commit is contained in:
parent
b117d385e9
commit
e95583b334
1 changed files with 15 additions and 0 deletions
|
@ -0,0 +1,15 @@
|
|||
class Solution {
|
||||
fun minimumOperations(nums: IntArray): Int =
|
||||
BooleanArray(101).let { seen ->
|
||||
for (num in nums.withIndex().reversed()) {
|
||||
when (seen[num.value]) {
|
||||
true -> {
|
||||
return num.index / 3 + 1
|
||||
}
|
||||
else -> seen[num.value] = true
|
||||
}
|
||||
}
|
||||
|
||||
0
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue