- Notifications
You must be signed in to change notification settings - Fork 1.3k
/
Copy path_3006.java
31 lines (29 loc) · 1.08 KB
/
_3006.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
packagecom.fishercoder.solutions.fourththousand;
importjava.util.ArrayList;
importjava.util.List;
publicclass_3006 {
publicstaticclassSolution1 {
publicList<Integer> beautifulIndices(Strings, Stringa, Stringb, intk) {
List<Integer> aIndices = newArrayList<>();
List<Integer> bIndices = newArrayList<>();
for (inti = 0; i < s.length(); i++) {
if ((i + a.length()) <= s.length() && s.substring(i, i + a.length()).equals(a)) {
aIndices.add(i);
}
if ((i + b.length()) <= s.length() && s.substring(i, i + b.length()).equals(b)) {
bIndices.add(i);
}
}
List<Integer> result = newArrayList<>();
for (intaIndex : aIndices) {
for (intbIndex : bIndices) {
if (Math.abs(aIndex - bIndex) <= k) {
result.add(aIndex);
break;
}
}
}
returnresult;
}
}
}