> For the complete documentation index, see [llms.txt](https://zcjian.gitbook.io/project/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://zcjian.gitbook.io/project/array/find-all-duplicates-in-an-array.md).

# Find All Duplicates in an Array

LeetCode 424

```python
class Solution:
    def findDuplicates(self, nums):
        """
        :type nums: List[int]
        :rtype: List[int]
        """
        """
        當提到時間複雜度可不可以使用O(n): (1) 2 pointers (2) index 法
        此題利用index
        1 <= a[i] <= n
        利用 index 來判斷 value 是否重複
        但須注意的是此題需要 index - 1
        """
        res = []
        for items in nums:
            
            if nums[abs(items)-1] < 0:
                # abs確保值為正數
                res.append(abs(items))
            else:
                nums[abs(items)-1] = - nums[abs(items)-1]
        return res
```
