-
Notifications
You must be signed in to change notification settings - Fork 0
/
Day6.java
39 lines (27 loc) · 1.01 KB
/
Day6.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
package com.gmail.legamemc.adventofcode2022.questions;
import com.gmail.legamemc.adventofcode2022.Challenge;
import com.gmail.legamemc.adventofcode2022.Utils;
import java.io.BufferedReader;
import java.util.ArrayDeque;
public class Day6 implements Challenge<Integer> {
private static final int DISTINCT_CHARACTER_COUNT = 14;
@Override
public Integer execute() throws Exception {
BufferedReader reader = Utils.getInputs(getClass());
String line = reader.readLine();
char[] arr = line.toCharArray();
ArrayDeque<Character> arrayDeque = new ArrayDeque<>();
int x = 0;
for(;x < arr.length && arrayDeque.size() != DISTINCT_CHARACTER_COUNT; x++){
if(arrayDeque.contains(arr[x])){
char removed;
do{
removed = arrayDeque.removeFirst();
}while(removed != arr[x]);
}
arrayDeque.add(arr[x]);
//System.out.println(arrayDeque);
}
return x;
}
}