class Solution {
public:
int removeDuplicates(vector<int>& nums) {
int n =nums.size();
if(n<=2)
return n;
int rIndex=1;
for(int i =2;i<n;i++)
{
int currentNumber=nums[i];
if(currentNumber==nums[rIndex]&¤tNumber==nums[rIndex-1])
continue;
nums[++rIndex]=nums[i];
}
return rIndex+1;
}
};
'Coding Test > LeetCode' 카테고리의 다른 글
26. Remove Duplicates from Sorted Array (0) | 2023.08.08 |
---|---|
27. Remove Element (0) | 2023.08.07 |
88. Merge Sorted Array (0) | 2023.08.07 |