idk if my idea is correct,but I really like it,if mine could be correct,plz give me the solution how to fix it,thx.
package com.codegym.task.task08.task0812;
import java.io.*;
import java.util.ArrayList;
import java.util.Collections;
/*
Longest sequence
*/
public class Solution {
public static void main(String[] args) throws IOException {
//write your code here
BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
ArrayList<Integer> list = new ArrayList<Integer>();
for(int i = 0 ; i < 10 ; i ++){
list.add(Integer.parseInt(reader.readLine()));
}
System.out.println(countlen(list));
}
public static int countlen(ArrayList list){
int count = 0;
for(int i = 0 ; i < list.size()-1 ; i ++){
if(list.get(i).equals(list.get(i+1))){
count++;
}
}
if(count ==0){
return 1;
}
else {
return 1+countlen(next(list));
}
}
public static ArrayList next(ArrayList list){
for(int i = 0 ; i < list.size()-1 ; i++){
if(!list.get(i).equals(list.get(i+1))){
list.remove(list.get(i));
}
list.remove(list.size()-1);
}
return list;
}
}