Hey! I just completed my day 2 challenge for 10days coding challenge with Ingressive4good. Today's task was to write a code that removes a given element from an array.
Here's my approach:
I need two arrays to achieve this, the first one is the given array while the second one is the new array without the elements.
I need two integers, the first to iterate through the given array while the second to generate the length of the new array
I need to check through the given array and return new array with the given value.
Initialize integer i to zero and declare integer k
Use for loop to iterate through nums array with condition: k < nums.length
check if each value of the array is not equal to the given element.
If not equal set nums[i] = nums[k] and increment i
Return the value of i.
Check out the code here Remove Element - LeetCode https://leetcode.com/problems/remove-element/submissions/
Top comments (0)