給出每個花的開花時間(起點終點),輸出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