[Python] Count, beats 100%, O(n * m)
First count the elements in each array, then find the number of triplets for each element.\nIt is faster if there are lots of duplicates.\n\nclass Solution(obje
First count the elements in each array, then find the number of triplets for each element.\nIt is faster if there are lots of duplicates.\n```\nclass Solution(object):\n    def numTriplets(self, nums1, nums2):\n        """\n        :type nums1: List[int]\n        :type nums2: List[int]\n        :rtype: int\n        """\n        cnt1 = collections.defaultdict(int)\n        cnt2 = collections.defaultdict(int)\n        for n in nums1:\n            cnt1[n] += 1\n        for n in nums2:\n            cnt2[n] += 1\n\n        def triplets(arr1, arr2):\n            ans = 0\n            for t, v in arr1.items():\n                k = arr2.get(t, 0)\n                tmp = k * (k - 1) // 2\n                sq = t * t\n                for m in arr2:\n                    if m < t and sq % m == 0:\n                        tmp += arr2.get(m, 0) * arr2.get(sq // m, 0)\n                ans += tmp * v\n            return ans\n        return triplets(cnt1, cnt2) + triplets(cnt2, cnt1)\n```
[]