We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 399a725 commit 4f18ff6Copy full SHA for 4f18ff6
src/main/java/com/sbaars/adventofcode/year22/days/Day6.java
@@ -3,7 +3,7 @@
3
import com.sbaars.adventofcode.year22.Day2022;
4
5
import java.io.IOException;
6
-import java.util.Set;
+import java.util.stream.IntStream;
7
8
public class Day6 extends Day2022 {
9
@@ -22,11 +22,7 @@ public Object part1() {
22
23
private int calculateAnswer(int size) {
24
String s = day();
25
- for(int i = 0; i<s.length(); i++){
26
- Set<Integer> chars = Set.copyOf(s.substring(i, i+size).chars().boxed().toList());
27
- if(chars.size() == size) return i+size;
28
- }
29
- return 0;
+ return IntStream.range(0, s.length()).filter(i -> s.substring(i, i+size).chars().distinct().count() == size).findFirst().getAsInt() + size;
30
}
31
32
@Override
0 commit comments