Skip to content

Commit 2c7de77

Browse files
authored
Create count-good-triplets.py
1 parent 8781907 commit 2c7de77

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

Python/count-good-triplets.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
# Time: O(n^3)
2+
# Space: O(1)
3+
4+
class Solution(object):
5+
def countGoodTriplets(self, arr, a, b, c):
6+
"""
7+
:type arr: List[int]
8+
:type a: int
9+
:type b: int
10+
:type c: int
11+
:rtype: int
12+
"""
13+
return sum(abs(arr[i]-arr[j]) <= a and
14+
abs(arr[j]-arr[k]) <= b and
15+
abs(arr[k]-arr[i]) <= c
16+
for i in xrange(len(arr)-2)
17+
for j in xrange(i+1, len(arr)-1)
18+
for k in xrange(j+1, len(arr)))
19+

0 commit comments

Comments
 (0)