【Leetcode】26. 配列内の重複を削除(Remove Duplicates from Sorted Array)


Leetcode - 26 Remove Duplicates from Sorted Array (Easy)
Given nums = [0,0,1,1,1,2,2,3,3,4],

Your function should return length = 5, with the first five elements of nums being modified to 0, 1, 2, 3, and 4 respectively.

It doesn't matter what values are set beyond the returned length.
public int removeDuplicates(int[] nums) {
     
    int index = 0;
    for (int i = 0; i < nums.length; i++) {
     
        if (i == 0 || nums[i] != nums[i - 1]) {
     
            nums[index++] = nums[i];
        }
    }
    return index;
}