2475. Number of Unequal Triplets in Array Easy
1/**
2 * [2475] Number of Unequal Triplets in Array
3 *
4 * You are given a 0-indexed array of positive integers nums. Find the number of triplets (i, j, k) that meet the following conditions:
5 *
6 * 0 <= i < j < k < nums.length
7 * nums[i], nums[j], and nums[k] are pairwise distinct.
8 *
9 * In other words, nums[i] != nums[j], nums[i] != nums[k], and nums[j] != nums[k].
10 *
11 *
12 *
13 * Return the number of triplets that meet the conditions.
14 *
15 * <strong class="example">Example 1:
16 *
17 * Input: nums = [4,4,2,4,3]
18 * Output: 3
19 * Explanation: The following triplets meet the conditions:
20 * - (0, 2, 4) because 4 != 2 != 3
21 * - (1, 2, 4) because 4 != 2 != 3
22 * - (2, 3, 4) because 2 != 4 != 3
23 * Since there are 3 triplets, we return 3.
24 * Note that (2, 0, 4) is not a valid triplet because 2 > 0.
25 *
26 * <strong class="example">Example 2:
27 *
28 * Input: nums = [1,1,1,1,1]
29 * Output: 0
30 * Explanation: No triplets meet the conditions so we return 0.
31 *
32 *
33 * Constraints:
34 *
35 * 3 <= nums.length <= 100
36 * 1 <= nums[i] <= 1000
37 *
38 */
39pub struct Solution {}
40
41// problem: https://leetcode.com/problems/number-of-unequal-triplets-in-array/
42// discuss: https://leetcode.com/problems/number-of-unequal-triplets-in-array/discuss/?currentPage=1&orderBy=most_votes&query=
43
44// submission codes start here
45
46impl Solution {
47 pub fn unequal_triplets(nums: Vec<i32>) -> i32 {
48 0
49 }
50}
51
52// submission codes end
53
54#[cfg(test)]
55mod tests {
56 use super::*;
57
58 #[test]
59 fn test_2475() {
60 }
61}
62
Back
© 2025 bowen.ge All Rights Reserved.