> For the complete documentation index, see [llms.txt](https://timmybeeflin.gitbook.io/cracking-leetcode/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://timmybeeflin.gitbook.io/cracking-leetcode/two-pointer/26.-remove-duplicates-from-sorted-array-1.md).

# 26. Remove Duplicates from Sorted Array

T: O(n)

S: O(1)

```java
class Solution {
    public int removeDuplicates(int[] nums) {
        int n = nums.length;
        int c = 1;
        
        for (int i = 1; i < n; i++) {
            if (nums[c-1] != nums[i]) {
                nums[c] = nums[i];
                c++;
            }
        }
        return c;
    }
}

```
