Skip to content

Instantly share code, notes, and snippets.

@paulosuzart
Last active November 30, 2018 23:39
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 paulosuzart/af2b3b544ac2fd282f6e6ca40c091bf7 to your computer and use it in GitHub Desktop.
Save paulosuzart/af2b3b544ac2fd282f6e6ca40c091bf7 to your computer and use it in GitHub Desktop.
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;
}
}
@avraamisvi
Copy link

Ficou top, mais enxuto que o meu.

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