Skip to content

Latest commit

 

History

History
43 lines (37 loc) · 851 Bytes

2475.数组中不等三元组的数目.md

File metadata and controls

43 lines (37 loc) · 851 Bytes

2475.数组中不等三元组的数目

/*
 * @lc app=leetcode.cn id=2475 lang=typescript
 *
 * [2475] 数组中不等三元组的数目
 */

// @lc code=start
function unequalTriplets(nums: number[]): number {}
// @lc code=end

解法 1: 暴力枚举

function unequalTriplets(nums: number[]): number {
  const n = nums.length
  let res = 0
  for (let i = 0; i < n; i++) {
    for (let j = i + 1; j < n; j++) {
      for (let k = j + 1; k < n; k++) {
        if (new Set([nums[i], nums[j], nums[k]]).size === 3) {
          res++
        }
      }
    }
  }
  return res
}

Case

test.each([
  { input: { nums: [4, 4, 2, 4, 3] }, output: 3 },
  { input: { nums: [1, 1, 1, 1, 1] }, output: 0 },
])('input: nums = $input.nums', ({ input: { nums }, output }) => {
  expect(unequalTriplets(nums)).toEqual(output)
})