删除有序数组中的重复项 II (Remove Duplicates from Sorted Array II)

 

思路:

// @Title: 删除有序数组中的重复项 II (Remove Duplicates from Sorted Array II)
// @Author: qisiii
// @Date: 2024-10-13 22:22:53
// @Runtime: 0 ms
// @Memory: 43.4 MB
// @comment: 
// @flag: GREEN
class Solution {
    public int removeDuplicates(int[] nums) {
        int write=0,cur=0,count=0,last=nums[0];
        while(cur<nums.length){
            if(nums[cur]!=last){
                count=0;
                last=nums[cur];
            }
            if(count<2){
                nums[write++]=nums[cur];
            }
            count++;
            cur++;
        }
        return write;
    }
}
Licensed under CC BY-NC-SA 4.0
最后更新于 2024-10-18