Created
August 8, 2019 07:40
-
-
Save yurist38/d5e83e228c72d681e8e202553df9ebde to your computer and use it in GitHub Desktop.
Daily Challenge #35 - Find the Outlier
This file contains hidden or 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
void main() { | |
print(findOutlier([2, 4, 0, 100, 4, 11, 2602, 36])); | |
print(findOutlier([160, 3, 1719, 19, 11, 13, -21])); | |
print(findOutlier([4, 8, 15, 16, 24, 42])); | |
print(findOutlier([16, 6, 40, 66, 68, 28])); | |
} | |
findOutlier(List nums) { | |
var odds = new List(); | |
var evens = new List(); | |
nums.forEach((num) => num % 2 == 0 ? evens.add(num) : odds.add(num)); | |
if (odds.length == 0 || evens.length == 0) { return null; } | |
return (odds.length < evens.length ? odds : evens)[0]; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment