給出每個(gè)花的開(kāi)花時(shí)間(起點(diǎn)終點(diǎn)),輸出people數(shù)組每個(gè)人到達(dá)時(shí)有多少花在開(kāi)。線段樹(shù)、掃描線、二分
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