From b22b0fa5e68ca97fb21770e7f41594c3d0d94e33 Mon Sep 17 00:00:00 2001 From: kagura Date: Tue, 15 Oct 2024 14:57:21 +0800 Subject: [PATCH] 1015 --- src/Test80.kt | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 src/Test80.kt diff --git a/src/Test80.kt b/src/Test80.kt new file mode 100644 index 0000000..2fdc074 --- /dev/null +++ b/src/Test80.kt @@ -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))) + } + +} \ No newline at end of file