Advertisement
butoff

Longest_Sequence

Nov 23rd, 2018
169
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.74 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. public class LongestSequence {
  4.  
  5.     public static void main(String[] args) {
  6.  
  7.         int longestSeq = 0;
  8.  
  9.         Scanner scanner = new Scanner(System.in);
  10.  
  11.         int cnt = scanner.nextInt();
  12.  
  13.         int previousNum = 0;
  14.         int currentSeq = 0;
  15.  
  16.         for (int i = 0; i < cnt; i++) {
  17.             int currentNum = scanner.nextInt();
  18.  
  19.             if (currentNum == previousNum){
  20.                 currentSeq++;
  21.             }
  22.             else{
  23.                 currentSeq = 1;
  24.             }
  25.  
  26.             previousNum = currentNum;
  27.  
  28.             if (currentSeq > longestSeq){
  29.                 longestSeq = currentSeq;
  30.             }
  31.         }
  32.  
  33.         System.out.println(longestSeq);
  34.     }
  35. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement