1534. Count Good Triplets Easy

@problem@discussion
#Array#Enumeration



1/**
2 * [1534] Count Good Triplets
3 *
4 * Given an array of integers arr, and three integers a, b and c. You need to find the number of good triplets.
5 * 
6 * A triplet (arr[i], arr[j], arr[k]) is good if the following conditions are true:
7 * 
8 * 
9 * 	0 <= i < j < k < arr.length
10 * 	|arr[i] - arr[j]| <= a
11 * 	|arr[j] - arr[k]| <= b
12 * 	|arr[i] - arr[k]| <= c
13 * 
14 * 
15 * Where |x| denotes the absolute value of x.
16 * 
17 * Return the number of good triplets.
18 * 
19 *  
20 * Example 1:
21 * 
22 * 
23 * Input: arr = [3,0,1,1,9,7], a = 7, b = 2, c = 3
24 * Output: 4
25 * Explanation: There are 4 good triplets: [(3,0,1), (3,0,1), (3,1,1), (0,1,1)].
26 * 
27 * 
28 * Example 2:
29 * 
30 * 
31 * Input: arr = [1,1,2,2,3], a = 0, b = 0, c = 1
32 * Output: 0
33 * Explanation: No triplet satisfies all conditions.
34 * 
35 * 
36 *  
37 * Constraints:
38 * 
39 * 
40 * 	3 <= arr.length <= 100
41 * 	0 <= arr[i] <= 1000
42 * 	0 <= a, b, c <= 1000
43 * 
44 */
45pub struct Solution {}
46
47// problem: https://leetcode.com/problems/count-good-triplets/
48// discuss: https://leetcode.com/problems/count-good-triplets/discuss/?currentPage=1&orderBy=most_votes&query=
49
50// submission codes start here
51
52impl Solution {
53    pub fn count_good_triplets(arr: Vec<i32>, a: i32, b: i32, c: i32) -> i32 {
54        0
55    }
56}
57
58// submission codes end
59
60#[cfg(test)]
61mod tests {
62    use super::*;
63
64    #[test]
65    fn test_1534() {
66    }
67}
68


Back
© 2025 bowen.ge All Rights Reserved.