> 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/remove-duplicates-from-sorted-array-1.md).

# Remove Duplicates from Sorted Array

Given a sorted array nums, remove the duplicates in-place and return the new length.

```python
class Solution:
    def removeDuplicates(self, nums):
        """
        :type nums: List[int]
        :rtype: int
        """
        if not nums:
            return 0
        c= 1
        """
        此題重點是要把數字往前搬(不是swap, 是直接assign) 然後用一個指標專門在前頭導引插入位置
         [1, 1, 1, 1, 1, 2, 3, 3]
             2  3
                   c
                            i
        """
        for i in range(1, len(nums)):
            if nums[i-1] != nums[i]:
                nums[c] = nums[i]
                c = c + 1
        return c
```
