92.45 %
class Solution {
public int removeDuplicates(int[] nums) {
if (nums == null || nums.length == 0) {
return 0;
}
// l r
// [0,0,1,1,1,2,2,3,3,4]
int left = 0;
int right = 0;
for (right = 0; right < nums.length; right++) {
if (nums[left] != nums[right]) {
left++;
nums[left] = nums[right];
}
}
return left + 1;
}
}
No comments:
Post a Comment