Skip to content

Commit e98ed75

Browse files
authored
Create tuple-with-same-product.py
1 parent 3ca6d5e commit e98ed75

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

Python/tuple-with-same-product.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
# Time: O(n^2)
2+
# Space: O(n^2)
3+
4+
import collections
5+
6+
7+
class Solution(object):
8+
def tupleSameProduct(self, nums):
9+
"""
10+
:type nums: List[int]
11+
:rtype: int
12+
"""
13+
result = 0
14+
count = collections.Counter()
15+
for i in xrange(len(nums)):
16+
for j in xrange(i+1, len(nums)):
17+
result += count[nums[i]*nums[j]]
18+
count[nums[i]*nums[j]] += 1
19+
return 8*result

0 commit comments

Comments
 (0)