Skip to content

Commit 5e1e3da

Browse files
add 3006
1 parent c7cc1e7 commit 5e1e3da

File tree

2 files changed

+32
-0
lines changed

2 files changed

+32
-0
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ _If you like this project, please leave me a star._ ★
88

99
| # | Title | Solutions | Video | Difficulty | Tag
1010
|------|----------------|------------------------------------------------------------------------------------------------------------------------------------------|-------------------------------------------------------------------------------|----------------------------------|-------------
11+
| 3006 |[Find Beautiful Indices in the Given Array I](https://leetcode.com/problems/find-beautiful-indices-in-the-given-array-i/)| [Java](../master/src/main/java/com/fishercoder/solutions/_3006.java) | | Easy |
1112
| 2716 |[Minimize String Length](https://leetcode.com/problems/minimize-string-length/)| [Java](../master/src/main/java/com/fishercoder/solutions/_2716.java) | [:tv:](https://youtu.be/aMJ3T0K8LjI) | Easy |
1213
| 2710 |[Remove Trailing Zeros From a String](https://leetcode.com/problems/remove-trailing-zeros-from-a-string/)| [Java](../master/src/main/java/com/fishercoder/solutions/_2710.java) | | Easy |
1314
| 2706 |[Buy Two Chocolates](https://leetcode.com/problems/buy-two-chocolates/)| [Java](../master/src/main/java/com/fishercoder/solutions/_2706.java) | | Easy |
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
package com.fishercoder.solutions;
2+
3+
import java.util.ArrayList;
4+
import java.util.List;
5+
6+
public class _3006 {
7+
public static class Solution1 {
8+
public List<Integer> beautifulIndices(String s, String a, String b, int k) {
9+
List<Integer> aIndices = new ArrayList<>();
10+
List<Integer> bIndices = new ArrayList<>();
11+
for (int i = 0; i < s.length(); i++) {
12+
if ((i + a.length()) <= s.length() && s.substring(i, i + a.length()).equals(a)) {
13+
aIndices.add(i);
14+
}
15+
if ((i + b.length()) <= s.length() && s.substring(i, i + b.length()).equals(b)) {
16+
bIndices.add(i);
17+
}
18+
}
19+
List<Integer> result = new ArrayList<>();
20+
for (int aIndex : aIndices) {
21+
for (int bIndex : bIndices) {
22+
if (Math.abs(aIndex - bIndex) <= k) {
23+
result.add(aIndex);
24+
break;
25+
}
26+
}
27+
}
28+
return result;
29+
}
30+
}
31+
}

0 commit comments

Comments
 (0)