Mishakis

LongestSequenceOfEqual

Nov 22nd, 2018
162
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.73 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. public class Main {
  4.  
  5.     public static void main(String[] args) {
  6.         Scanner scanner = new Scanner(System.in);
  7.  
  8.         int n = scanner.nextInt();
  9.  
  10.         int[] array = new int[n];
  11.  
  12.         for (int i = 0; i < array.length; i++) {
  13.             array[i] = scanner.nextInt();
  14.         }
  15.  
  16.         int maxCount = 0;
  17.         int current = 1;
  18.  
  19.         for (int i = 1; i < array.length; i++) {
  20.             if (array[i] == array[i - 1]) {
  21.                 current++;
  22.                 maxCount = Math.max(maxCount, current);
  23.             } else {
  24.                 maxCount = Math.max(maxCount, current);
  25.                 current = 1;
  26.             }
  27.         }
  28.         System.out.println(maxCount);
  29.     }
  30. }
Advertisement
Add Comment
Please, Sign In to add comment