Skip to content

Instantly share code, notes, and snippets.

@Ezeji
Created April 16, 2021 23:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Ezeji/49b06d3d56850ea3d2356dcf792dd847 to your computer and use it in GitHub Desktop.
Save Ezeji/49b06d3d56850ea3d2356dcf792dd847 to your computer and use it in GitHub Desktop.
This algorithm focuses on removing number instances.
public static int RemoveNumberInstances(int[] nums, int val)
{
if (nums == null)
{
return 0;
}
else
{
nums = nums.Where(arrayElement => arrayElement != val).ToArray();
return nums.Length;
}
}
@meekg33k
Copy link

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 is null. Neat!

That said, the logic for your solution uses a Where filter function that only returns the elements in nums whose values are not equal to val. What do you think are the trade-offs with using the Where function? Is it really memory-optimal to use this approach?

I've posted my solution here. I am curious to know what you think.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment