Remove Element Leetcode Coding challenge Google, Tiktok amazon coding Interviews
Пікірлер: 2
@kenaida228 ай бұрын
What about using the filter method? Especially easy in javascript? Would this work: return nums.filter(x => x != val).length;
@codingforbeginners44138 ай бұрын
Hi Kenaida, so using filter method would create a new array and not actually modifying the original array (which is required in the problem statement, which is to change nums array), using filter would mean to store all values not equal to val and then reassigning them to the nums[i] so also this will take more space as of space complexity O(n)