题目描述
解答:
var removeDuplicates = function(nums) {
nums.map((item,index) => {
for(let i = 0; i < nums.length; i++){
if(item === nums[i] && i !== index ){
nums.splice(i,1)
i--
}
}
})
return nums.length
};
var removeDuplicates = function (nums) {
const size = nums.length;
let slowP = 0;
for (let fastP = 0; fastP < size; fastP++) {
if (nums[fastP] !== nums[slowP]) {
slowP++;
nums[slowP] = nums[fastP]
}
}
return slowP + 1;
};