vmacinski95

BiggestSequence

Apr 27th, 2021
97
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.81 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. public class BiggestSequence {
  4.     public static void main(String[] args) {
  5.         Scanner scanner = new Scanner(System.in);
  6.         int numb = scanner.nextInt();
  7.         int[] sequence = new int[numb];
  8.         for (int i = 0; i < sequence.length; i++) {
  9.             sequence[i] = scanner.nextInt();
  10.         }
  11.         int counter = 1;
  12.         int max = Integer.MIN_VALUE;
  13.         for (int j = 0; j < sequence.length; j++) {
  14.             if (j != 0) {
  15.                 if (sequence[j - 1] == sequence[j]) {
  16.                     counter++;
  17.                     if (counter >= max) {
  18.                         max = counter;
  19.                     }
  20.                 } else {
  21.                     counter = 1;
  22.                 }
  23.             }
  24.         }
  25.         System.out.println(max);
  26.     }
  27. }
Advertisement
Add Comment
Please, Sign In to add comment