# 26. Remove Duplicates from Sorted Array

{% embed url="<https://leetcode.com/problems/remove-duplicates-from-sorted-array/>" %}

比较简单且直观的遍历，一直跟之前的subarray比较就行，有重复就删掉。利用`sorted array`这个条件，就只需要和前项比较。

```python
class Solution:
    def removeDuplicates(self, nums: List[int]) -> int:
        i = 1
        while i < len(nums):
            if nums[i] == nums[i-1]: 
                del nums[i]
            else: 
                i += 1
        return len(nums)
```
