/** * @param {number[]} nums * @param {number} val * @return {number} */ var removeElement = function(nums, val) { let j = 0 for(let i = 0, size = nums.length; i<size; i++) { if(nums[i] !== val) { nums[j] = nums[i] j++ } } return j };
/** * @param {number[]} nums * @param {number} val * @return {number} */ var removeElement = function(nums, val) { let i = 0 let n = nums.length while(i<n) { if(nums[i] === val) { nums[i] = nums[n-1] n-- } else { i++ } } return n };