Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner;
- public class LongestSequence {
- public static void main(String[] args) {
- int longestSeq = 0;
- Scanner scanner = new Scanner(System.in);
- int cnt = scanner.nextInt();
- int previousNum = 0;
- int currentSeq = 0;
- for (int i = 0; i < cnt; i++) {
- int currentNum = scanner.nextInt();
- if (currentNum == previousNum){
- currentSeq++;
- }
- else{
- currentSeq = 1;
- }
- previousNum = currentNum;
- if (currentSeq > longestSeq){
- longestSeq = currentSeq;
- }
- }
- System.out.println(longestSeq);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement