From 69eca60bb4f25985de872410121f5f77ff47c70d Mon Sep 17 00:00:00 2001 From: Won Joon Thomas Choi <113500771+724thomas@users.noreply.github.com> Date: Wed, 4 Nov 2026 14:37:28 +0000 Subject: [PATCH 1/2] Create 442. Find All Duplicates in an Array.py --- .../442. Find All Duplicates in an Array.py" | 3 +++ 1 file changed, 3 insertions(+) create mode 100644 "leetcode3/\354\265\234\354\233\220\354\244\200/442. Find All Duplicates in an Array.py" diff --git "a/leetcode3/\354\265\234\354\233\220\354\244\200/442. Find All Duplicates in an Array.py" "b/leetcode3/\354\265\234\354\233\220\354\244\200/442. Find All Duplicates in an Array.py" new file mode 100644 index 00000000..87317023 --- /dev/null +++ "b/leetcode3/\354\265\234\354\233\220\354\244\200/442. Find All Duplicates in an Array.py" @@ -0,0 +1,3 @@ +class Solution: + def findDuplicates(self, nums: list[int]) -> list[int]: + return [num for num, count in Counter(nums).items() if count == 2] From aea293218fc1329992b0a5295fd092361221dd8d Mon Sep 17 00:00:00 2001 From: Won Joon Thomas Choi <113500771+724thomas@users.noreply.github.com> Date: Wed, 4 Nov 2026 23:39:58 +0900 Subject: [PATCH 2/2] Update 442. Find All Duplicates in an Array.py --- .../442. Find All Duplicates in an Array.py" | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git "a/leetcode3/\354\265\234\354\233\220\354\244\200/442. Find All Duplicates in an Array.py" "b/leetcode3/\354\265\234\354\233\220\354\244\200/442. Find All Duplicates in an Array.py" index 87317023..d38e9d84 100644 --- "a/leetcode3/\354\265\234\354\233\220\354\244\200/442. Find All Duplicates in an Array.py" +++ "b/leetcode3/\354\265\234\354\233\220\354\244\200/442. Find All Duplicates in an Array.py" @@ -1,3 +1,19 @@ class Solution: def findDuplicates(self, nums: list[int]) -> list[int]: return [num for num, count in Counter(nums).items() if count == 2] + + + +class Solution: + def findDuplicates(self, nums: list[int]) -> list[int]: + result = [] + + for num in nums: + idx = abs(num) - 1 + + if nums[idx] < 0: + result.append(abs(num)) + else: + nums[idx] *= -1 + + return result