Skip to content

Commit 260b660

Browse files
authored
Create number-of-distinct-averages.py
1 parent c76244b commit 260b660

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

Python/number-of-distinct-averages.py

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
# Time: O(nlogn)
2+
# Space: O(n)
3+
4+
# sort, two pointers, hash table
5+
class Solution(object):
6+
def distinctAverages(self, nums):
7+
"""
8+
:type nums: List[int]
9+
:rtype: int
10+
"""
11+
lookup = set()
12+
nums.sort()
13+
left, right = 0, len(nums)-1
14+
while left < right:
15+
lookup.add(nums[left]+nums[right])
16+
left, right = left+1, right-1
17+
return len(lookup)

0 commit comments

Comments
 (0)