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++;
- }
- else if (arr[i] < arr[i + 1]) {
- if (tempCounter < counter) {
- tempCounter = counter;
- mostCommon = arr[i];
- }
- counter = 0;
- }
- }
- return mostCommon;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement