/**
* @param {number[]} nums
* @param {number} val
* @return {number}
*/
var removeElement = function(nums, val) {
var index = 0;
for (const num of nums) {
if (num != val) {
nums[index] = num;
index++;
}
}
return index;
};
Pages
Showing posts with label Remove Element. Show all posts
Showing posts with label Remove Element. Show all posts
Wednesday, 2 August 2023
LeetCode - 27 - Remove Element
LeetCode - 26 - Remove Duplicates from Sorted Array
/**
* @param {number[]} nums
* @return {number}
*/
var removeDuplicates = function(nums) {
var index = 0;
var last = 200;
for(const num of nums) {
if (num != last) {
nums[index] = num;
index++;
}
last = num;
}
return index;
};
Subscribe to:
Posts (Atom)