-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path1534-Count-good-triplets.cs
More file actions
52 lines (46 loc) · 1.53 KB
/
1534-Count-good-triplets.cs
File metadata and controls
52 lines (46 loc) · 1.53 KB
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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
using System;
using System.Collections.Generic;
using System.Text;
namespace Solution._1534.Count_good_triplets
{
public class _1534_Count_good_triplets
{
public int CountGoodTriplets(int[] arr, int a, int b, int c)
{
int count = 0;
for (int i = 0; i < arr.Length; i++)
{
for (int j = i + 1; j < arr.Length; j++)
{
if (Math.Abs(arr[i] - arr[j]) > a) continue;
for (int k = j + 1; k < arr.Length; k++)
{
if (Math.Abs(arr[j] - arr[k]) > b) continue;
if (Math.Abs(arr[i] - arr[k]) > c) continue;
count++;
}
}
}
//for (int i = 0; i < arr.Length; i++)
//{
// for (int j = i + 1; j < arr.Length; j++)
// {
// if (Math.Abs(arr[i] - arr[j]) <= a)
// {
// for (int k = j + 1; k < arr.Length; k++)
// {
// if (Math.Abs(arr[j] - arr[k]) <= b)
// {
// if (Math.Abs(arr[i] - arr[k]) <= c)
// {
// count++;
// }
// }
// }
// }
// }
//}
return count;
}
}
}