---
description: LeetCode 26
---

# Remove Duplicates from Sorted Array

```python
class Solution:
    def removeDuplicates(self, nums):
        """
        :type nums: List[int]
        :rtype: int
        """
        """
        此題解題思路為
        2 pointers, 數字 copy 而非 swap
        """
        if not nums:
            return 0
        c= 1
        # [1, 1, 2, 2, 3, 3]
        # [1, 2, 3, 2, 3, 3]
        #           c
        #                 i
        for i in range(1, len(nums)):
            if nums[i-1] != nums[i]:
                nums[c] = nums[i]
                c = c + 1
        # return nums[:c]         
        return c
```
