Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public static int mostCommonNum(int[] arr) {
- int mostCommon = arr[0];
- int counter = 0;
- int tempCounter = 0;
- for (int i = 0; i < arr.length - 1; i++) {
- if (arr[i] == arr[i + 1]) {
- counter++;
- mostCommon = arr[i];
- } else
- counter = tempCounter > counter ? tempCounter : counter;
- }
- return mostCommon;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement