Last active
November 30, 2018 23:39
-
-
Save paulosuzart/af2b3b544ac2fd282f6e6ca40c091bf7 to your computer and use it in GitHub Desktop.
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
public class FindOutlier { | |
public static int find(int[] numbers) { | |
int lastOdd = 0; | |
int lastEven = 0; | |
int totalOdd = 0; | |
int totalEven = 0; | |
for (int i = 0; i < numbers.length; i++) { | |
if (numbers[i] % 2 == 0) { | |
totalEven++; | |
lastEven = numbers[i]; | |
} else { | |
totalOdd++; | |
lastOdd = numbers[i]; | |
} | |
} | |
return totalOdd > totalEven ? lastEven : lastOdd; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Ficou top, mais enxuto que o meu.