---
# System prepended metadata

title: Leetcode 26.

---

# Leetcode 26. Remove Duplicates from Sorted Array

# 題解

## 雙指針

![](https://i.imgur.com/V1OPytk.jpeg)

```python!
class Solution:
    def removeDuplicates(self, nums: List[int]) -> int:
        n = len(nums)
        i = j = 1
        while j < n:
            if nums[j] != nums[j-1]: # 找不不同 i 再走
                nums[i] = nums[j]
                i += 1
            j += 1 # 持續找不同
        return i # 最後 i 會在邊界上
```
