diff --git a/solution/0400-0499/0442.Find All Duplicates in an Array/README.md b/solution/0400-0499/0442.Find All Duplicates in an Array/README.md index ef097526e76fc..949d1e933d057 100644 --- a/solution/0400-0499/0442.Find All Duplicates in an Array/README.md +++ b/solution/0400-0499/0442.Find All Duplicates in an Array/README.md @@ -146,6 +146,27 @@ func findDuplicates(nums []int) []int { } ``` +#### TypeScript + +```ts +function findDuplicates(nums: number[]): number[] { + for (let i = 0; i < nums.length; i++) { + while (nums[i] !== nums[nums[i] - 1]) { + const temp = nums[i]; + nums[i] = nums[temp - 1]; + nums[temp - 1] = temp; + } + } + const ans: number[] = []; + for (let i = 0; i < nums.length; i++) { + if (nums[i] !== i + 1) { + ans.push(nums[i]); + } + } + return ans; +} +``` + diff --git a/solution/0400-0499/0442.Find All Duplicates in an Array/README_EN.md b/solution/0400-0499/0442.Find All Duplicates in an Array/README_EN.md index 013557eeb986e..8a3feeb89f721 100644 --- a/solution/0400-0499/0442.Find All Duplicates in an Array/README_EN.md +++ b/solution/0400-0499/0442.Find All Duplicates in an Array/README_EN.md @@ -133,6 +133,27 @@ func findDuplicates(nums []int) []int { } ``` +#### TypeScript + +```ts +function findDuplicates(nums: number[]): number[] { + for (let i = 0; i < nums.length; i++) { + while (nums[i] !== nums[nums[i] - 1]) { + const temp = nums[i]; + nums[i] = nums[temp - 1]; + nums[temp - 1] = temp; + } + } + const ans: number[] = []; + for (let i = 0; i < nums.length; i++) { + if (nums[i] !== i + 1) { + ans.push(nums[i]); + } + } + return ans; +} +``` + diff --git a/solution/0400-0499/0442.Find All Duplicates in an Array/Solution.ts b/solution/0400-0499/0442.Find All Duplicates in an Array/Solution.ts new file mode 100644 index 0000000000000..ed9cd7d2d95ab --- /dev/null +++ b/solution/0400-0499/0442.Find All Duplicates in an Array/Solution.ts @@ -0,0 +1,16 @@ +function findDuplicates(nums: number[]): number[] { + for (let i = 0; i < nums.length; i++) { + while (nums[i] !== nums[nums[i] - 1]) { + const temp = nums[i]; + nums[i] = nums[temp - 1]; + nums[temp - 1] = temp; + } + } + const ans: number[] = []; + for (let i = 0; i < nums.length; i++) { + if (nums[i] !== i + 1) { + ans.push(nums[i]); + } + } + return ans; +} diff --git a/solution/2200-2299/2283.Check if Number Has Equal Digit Count and Digit Value/Solution.go b/solution/2200-2299/2283.Check if Number Has Equal Digit Count and Digit Value/Solution.go index abb22e8f7a4f2..168c7124bee8a 100644 --- a/solution/2200-2299/2283.Check if Number Has Equal Digit Count and Digit Value/Solution.go +++ b/solution/2200-2299/2283.Check if Number Has Equal Digit Count and Digit Value/Solution.go @@ -9,4 +9,4 @@ func digitCount(num string) bool { } } return true -} \ No newline at end of file +}