This commit is contained in:
kagura 2024-10-15 14:57:21 +08:00
parent 69f4005e9c
commit b22b0fa5e6

23
src/Test80.kt Normal file
View file

@ -0,0 +1,23 @@
class Test80 {
class Solution {
fun removeDuplicates(nums: IntArray): Int {
if (nums.size <= 2){
return nums.size
}
var slow = 1
for (fast in 2.. nums.lastIndex){
if (nums[fast] != nums[slow] || nums[slow] != nums[slow-1]) {
nums[++slow] = nums[fast]
}
}
return slow +1
}
}
fun test(){
println(Solution().removeDuplicates(intArrayOf(0,0,1,1,1,1,2,3,3)))
}
}