image

[Link] https://leetcode.com/problems/remove-duplicates-from-sorted-array/


1
2
3
4
5
6
7
8
9
10
class Solution {
    public int removeDuplicates(int[] nums) {
      int newIdx = 0, curIdx = 1;
      while(curIdx < nums.length) {
        if(nums[curIdx] != nums[newIdx]) nums[++newIdx] = nums[curIdx];
        curIdx++;
      }
      return newIdx + 1;
    }
}