题目描述
思路:快慢指针
slow指针:指向已经处理的区域(没有重复元素)的最后一个位置
fast指针:指向当前正在处理的元素
方法一:
class Solution {
public int removeDuplicates(int[] nums) {
int slow = 0, fast = 0;
for (; fast < nums.length; fast ++) {
if (nums[fast] != nums[slow]) {
slow ++;
nums[slow] = nums[fast];
}
}
return slow + 1;
}
}
标签:slow,nums,int,fast,数组,LeetCode26,指针,刷题
From: https://www.cnblogs.com/keyongkang/p/17963556