-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDay 54
More file actions
28 lines (21 loc) · 691 Bytes
/
Day 54
File metadata and controls
28 lines (21 loc) · 691 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
#
class Solution:
def countTrapezoids(self, points: List[List[int]]) -> int:
MOD = 10**9 + 7
from collections import defaultdict
y_groups = defaultdict(int)
for x, y in points:
y_groups[y] += 1
seg_counts = []
for k in y_groups.values():
if k >= 2:
seg_counts.append(k*(k-1)//2 % MOD)
if len(seg_counts) < 2:
return 0
seg_counts.sort()
total = 0
prefix = 0
for v in seg_counts:
total = (total + v * prefix) % MOD
prefix = (prefix + v) % MOD
return total % MOD