Last active
April 27, 2021 10:24
-
-
Save deedee47/88585a284c8191e6af9960a758601dd3 to your computer and use it in GitHub Desktop.
Returns new count of elements in a Numbers array excluding occurrences of a specified value
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 int countOfElementsExcludingVal(int[] nums, int val){ | |
if(nums == null) return 0; | |
int countWithoutVal = nums.length; | |
for(int item : nums){ | |
if (item == val) countWithoutVal--; | |
} | |
return countWithoutVal; | |
} |
No worries, glad you found it insightful!
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hi @meekg33k, thank you for your comment.
I have gone through your solution, really insightful with the double-pointer approach. Thank you