public class Solution { public int CountGoodTriplets(int[] arr, int a, int b, int c) { int goodTriplets = 0; for (var i = 0; i < arr.Length - 2; ++i) for (var j = i + 1; j < arr.Length - 1; ++j) for (var k = j + 1; k < arr.Length; ++k) { if (Math.Abs(arr[i] - arr[j]) <= a && Math.Abs(arr[j] - arr[k]) <= b && Math.Abs(arr[i] - arr[k]) <= c) { ++goodTriplets; } } return goodTriplets; } }Source: https://leetcode.com/problems/count-good-triplets/
"Simplicity can't be bought later, it must be earned from the start" -- DB
Sunday, February 21, 2021
Leetcode Everyday: 1534. Count Good Triplets. Easy
Labels:
leetcode
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment