1015
This commit is contained in:
parent
69f4005e9c
commit
b22b0fa5e6
1 changed files with 23 additions and 0 deletions
23
src/Test80.kt
Normal file
23
src/Test80.kt
Normal 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)))
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in a new issue