Created
April 16, 2021 23:05
-
-
Save Ezeji/49b06d3d56850ea3d2356dcf792dd847 to your computer and use it in GitHub Desktop.
This algorithm focuses on removing number instances.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public static int RemoveNumberInstances(int[] nums, int val) | |
{ | |
if (nums == null) | |
{ | |
return 0; | |
} | |
else | |
{ | |
nums = nums.Where(arrayElement => arrayElement != val).ToArray(); | |
return nums.Length; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hello @Ezeji, thank you for participating in Week 2 of Algorithm Fridays.
Really decent and robust solution you got here - your solution correctly handles the edge case where the input value for the
nums
array isnull
. Neat!That said, the logic for your solution uses a
Where
filter function that only returns the elements innums
whose values are not equal toval
. What do you think are the trade-offs with using theWhere
function? Is it really memory-optimal to use this approach?I've posted my solution here. I am curious to know what you think.