给出每个花的开花时间(起点终点),输出people数组每个人到达时有多少花在开。线段树、扫描线、二分
1 #2251
2 #Runtime: 1083 ms (Beats 15.71%)
3 #Memory: 44.7 MB (Beats 32.83%)
4
5 class Solution:
6 def fullBloomFlowers(self, flowers: List[List[int]], people: List[int]) -> List[int]:
7 st = sorted(flowers, key=lambda x:x[0])
8 ed = sorted(flowers, key=lambda x:x[1])
9 ans = []
10 for x in people:
11 i = bisect_left(ed, x, key=lambda x:x[1])
12 j = bisect_right(st, x, key=lambda x:x[0])
13 ans.append(j - i)
14 return ans