Skip to content

Latest commit

 

History

History
20 lines (18 loc) · 459 Bytes

2475.md

File metadata and controls

20 lines (18 loc) · 459 Bytes

2475. Number of Unequal Triplets in Array

Solution 1 (time O(n), space O(n))

class Solution(object):
    def unequalTriplets(self, nums):
        """
        :type nums: List[int]
        :rtype: int
        """
        cnt = collections.Counter(nums)
        n = len(nums)
        ans = a = 0
        for b in cnt.values():
            c = n - a - b
            ans += a * b * c
            a += b
        return ans