Problem: 80. 删除有序数组中的重复项 II
思路
复杂度
时间复杂度: O ( n ) O(n) O(n)
空间复杂度: O ( 1 ) O(1) O(1)
Code
class Solution {
public int removeDuplicates(int[] nums) {
int idx = 1;
int n = nums.length;
for(int i = 2; i < n; i++)
{
if(nums[i] != nums[idx-1])
nums[++idx] = nums[i];
}
return idx+1;
}
}