27. Remove Element

202410011622
tags: #array #two-pointers

var removeElement = function(nums, val) {
	let len = 0;
	for (let i = 0; i < nums.length; i++) {
		if (nums[i] !== val) {
			nums[len] = nums[i];
			len += 1;
		}
	}
	return len;
};

Reference

https://leetcode.com/problems/remove-element/