From 7065720ff65461eb3bcf02a283b0940ac9bf03ac Mon Sep 17 00:00:00 2001 From: argondev22 Date: Tue, 28 Oct 2025 06:54:42 +0900 Subject: [PATCH] Add implementation for removing duplicates from a sorted array in TypeScript. The function modifies the input array in place and returns the new length of the array. --- .../26_remove-duplicates-from-sorted-array/20251028.ts | 10 ++++++++++ 1 file changed, 10 insertions(+) create mode 100644 src/leetcode/26_remove-duplicates-from-sorted-array/20251028.ts diff --git a/src/leetcode/26_remove-duplicates-from-sorted-array/20251028.ts b/src/leetcode/26_remove-duplicates-from-sorted-array/20251028.ts new file mode 100644 index 0000000..95a6bac --- /dev/null +++ b/src/leetcode/26_remove-duplicates-from-sorted-array/20251028.ts @@ -0,0 +1,10 @@ +export function removeDuplicates(nums: number[]): number { + let k = 1 + for (let i = 1; i < nums.length; i++) { + if (nums[i - 1] !== nums[i]) { + nums[k] = nums[i] + k++ + } + } + return k; +}