LeetCode 80 Remove Duplicates from Sorted Array II | JSer - JavaScript & Algorithm

preview_player
Показать описание
LeetCode 80 Remove Duplicates from Sorted Array II
Just a slight variation from problem 26. please search on my channel for that

Hi I'm a JavaScript engineer who is not good at algorithms,
and currently practicing leetCode online. If you are interested, maybe we can learn together.
Рекомендации по теме
Комментарии
Автор

/**
* @param {number[]} nums
* @return {number}
*/
var removeDuplicates = function(nums) {
let p1 = 0;
let p2 = 0;
let count = 0;
while(p2 < nums.length){
if(nums[p2] !== nums[p2 -1]){
count = 1
nums[p1] = nums[p2]
p1 += 1
}else{
count += 1
if(count <= 2){
nums[p1] = nums[p2]
p1 += 1
}
}
p2 += 1
}
return 1
};

crisp
Автор

Dude first learn by yourself than teach others

parthavpatel
welcome to shbcf.ru