MCPcopy Create free account
hub / github.com/StudyRust/leetcode_rust / count_good_triplets

Function count_good_triplets

1534-count-good-triplets.rs:1–15  ·  view source on GitHub ↗
(arr: Vec<i32>, a: i32, b: i32, c: i32)

Source from the content-addressed store, hash-verified

1pub fn count_good_triplets(arr: Vec<i32>, a: i32, b: i32, c: i32) -> i32 {
2 let mut ret = 0;
3 for i in 0..arr.len() {
4 for j in (i+1)..arr.len() {
5 for k in (j+1)..arr.len() {
6 if (arr[i] - arr[j]).abs() <= a &&
7 (arr[j] - arr[k]).abs() <= b &&
8 (arr[i] - arr[k]).abs() <= c {
9 ret += 1;
10 }
11 }
12 }
13 }
14 ret
15}
16
17fn main() {
18 let arr = vec![3,0,1,1,9,7];

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected