Count Good Triplets LeetCode solution in Python

1
# Runtime: 1794 ms (Top 11.20%) | Memory: 13.8 MB (Top 87.90%)
2
class Solution:
3
def countGoodTriplets(self, arr: List[int], a: int, b: int, c: int) -> int:
4
count = 0
5
for i in range(len(arr)):
6
for j in range(i + 1, len(arr)):
7
for k in range(j + 1, len(arr)):
8
if (
9
abs(arr[i] - arr[j]) <= a
10
and abs(arr[j] - arr[k]) <= b
11
and abs(arr[k] - arr[i]) <= c
12
):
13
count += 1
14
return count

0

WPM •0 •0

100%

ACC •0 •0

0s

TIME •0