I can't pass the last task, the following is my code:
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<>();
for(int i = 0; i < 10; i++) {
int num = Integer.parseInt(reader.readLine());
list.add(num);
}
int result = 1, sub = 1, front = list.get(0);
for(int i = 1; i < list.size(); i++) {
int num = list.get(i);
if (front == num) {
sub++;
} else {
if(sub > result){
result = sub;
}
front = num;
sub = 1;
}
}
System.out.println(result);
}
}
And the hint says: Be sure that the length of the longest sequence is calculated correctly when it is located at the end of the list of entered numbers.
Could you please tell me how to fix it? thanks for your help!