Skip to content

Commit 7a587ce

Browse files
add 1534
1 parent b813604 commit 7a587ce

File tree

3 files changed

+44
-0
lines changed

3 files changed

+44
-0
lines changed

README.md

+1
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+
|1534|[Count Good Triplets](https://leetcode.com/problems/count-good-triplets/)|[Solution](../master/src/main/java/com/fishercoder/solutions/_1534.java) | |Easy|Array|
1112
|1528|[Shuffle String](https://leetcode.com/problems/shuffle-string/)|[Solution](../master/src/main/java/com/fishercoder/solutions/_1528.java) | |Easy|Sort|
1213
|1526|[Minimum Number of Increments on Subarrays to Form a Target Array](https://leetcode.com/problems/minimum-number-of-increments-on-subarrays-to-form-a-target-array/)|[Solution](../master/src/main/java/com/fishercoder/solutions/_1526.java) | |Hard|Segment Tree|
1314
|1525|[Number of Good Ways to Split a String](https://leetcode.com/problems/number-of-good-ways-to-split-a-string/)|[Solution](../master/src/main/java/com/fishercoder/solutions/_1525.java) | |Medium|String, Bit Manipulation|
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
package com.fishercoder.solutions;
2+
3+
public class _1534 {
4+
public static class Solution1 {
5+
public int countGoodTriplets(int[] arr, int a, int b, int c) {
6+
int count = 0;
7+
for (int i = 0; i < arr.length - 2; i++) {
8+
for (int j = i + 1; j < arr.length - 1; j++) {
9+
for (int k = j + 1; k < arr.length; k++) {
10+
if (Math.abs(arr[i] - arr[j]) <= a && Math.abs(arr[j] - arr[k]) <= b && Math.abs(arr[i] - arr[k]) <= c) {
11+
count++;
12+
}
13+
}
14+
}
15+
}
16+
return count;
17+
}
18+
}
19+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
package com.fishercoder;
2+
3+
import com.fishercoder.solutions._1534;
4+
import org.junit.BeforeClass;
5+
import org.junit.Test;
6+
7+
import static junit.framework.TestCase.assertEquals;
8+
9+
public class _1534Test {
10+
private static _1534.Solution1 solution1;
11+
private static int[] arr;
12+
13+
@BeforeClass
14+
public static void setup() {
15+
solution1 = new _1534.Solution1();
16+
}
17+
18+
@Test
19+
public void test1() {
20+
arr = new int[]{3, 0, 1, 1, 9, 7};
21+
assertEquals(4, solution1.countGoodTriplets(arr, 7, 2, 3));
22+
}
23+
24+
}

0 commit comments

Comments
 (0)