---
description: LeetCode 424
---

# Find All Duplicates in an Array

```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
```
