java.lang.Object
g2401_2500.s2475_number_of_unequal_triplets_in_array.Solution

public class Solution extends Object
2475 - Number of Unequal Triplets in Array.<p>Easy</p> <p>You are given a <strong>0-indexed</strong> array of positive integers <code>nums</code>. Find the number of triplets <code>(i, j, k)</code> that meet the following conditions:</p> <ul> <li><code>0 <= i < j < k < nums.length</code></li> <li><code>nums[i]</code>, <code>nums[j]</code>, and <code>nums[k]</code> are <strong>pairwise distinct</strong>. <ul> <li>In other words, <code>nums[i] != nums[j]</code>, <code>nums[i] != nums[k]</code>, and <code>nums[j] != nums[k]</code>.</li> </ul> </li> </ul> <p>Return <em>the number of triplets that meet the conditions.</em></p> <p><strong>Example 1:</strong></p> <p><strong>Input:</strong> nums = [4,4,2,4,3]</p> <p><strong>Output:</strong> 3</p> <p><strong>Explanation:</strong> The following triplets meet the conditions:</p> <ul> <li>(0, 2, 4) because 4 != 2 != 3</li> <li>(1, 2, 4) because 4 != 2 != 3</li> <li>(2, 3, 4) because 2 != 4 != 3 Since there are 3 triplets, we return 3. Note that (2, 0, 4) is not a valid triplet because 2 > 0.</li> </ul> <p><strong>Example 2:</strong></p> <p><strong>Input:</strong> nums = [1,1,1,1,1]</p> <p><strong>Output:</strong> 0</p> <p><strong>Explanation:</strong> No triplets meet the conditions so we return 0.</p> <p><strong>Constraints:</strong></p> <ul> <li><code>3 <= nums.length <= 100</code></li> <li><code>1 <= nums[i] <= 1000</code></li> </ul>
  • Constructor Details

    • Solution

      public Solution()
  • Method Details

    • unequalTriplets

      public int unequalTriplets(int[] nums)