class Solution:
def fullBloomFlowers(self, flowers: List[List[int]], people: List[int]) -> List[int]:
res = []
for time in people:
cnt = 0
for start, end in flowers:
if start <= time <= end:
cnt += 1
res.append(cnt)
return resWhere is the size of the array , and is the size of the array .
class Solution:
def fullBloomFlowers(self, flowers: List[List[int]], people: List[int]) -> List[int]:
people = sorted((p, i) for i, p in enumerate(people))
res = [0] * len(people)
count = 0
start = [f[0] for f in flowers]
end = [f[1] for f in flowers]
heapq.heapify(start)
heapq.heapify(end)
for p, i in people:
while start and start[0] <= p:
heapq.heappop(start)
count += 1
while end and end[0] < p:
heapq.heappop(end)
count -= 1
res[i] = count
return resWhere is the size of the array , and is the size of the array .
class Solution:
def fullBloomFlowers(self, flowers: List[List[int]], people: List[int]) -> List[int]:
people = sorted((p, i) for i, p in enumerate(people))
res = [0] * len(people)
flowers.sort()
end = []
j = 0
for p, i in people:
while j < len(flowers) and flowers[j][0] <= p:
heapq.heappush(end, flowers[j][1])
j += 1
while end and end[0] < p:
heapq.heappop(end)
res[i] = len(end)
return resWhere is the size of the array , and is the size of the array .
class Solution:
def fullBloomFlowers(self, flowers: List[List[int]], people: List[int]) -> List[int]:
start = sorted(f[0] for f in flowers)
end = sorted(f[1] for f in flowers)
res = [0] * len(people)
peopleIndex = sorted((p, i) for i, p in enumerate(people))
i = j = count = 0
for p, index in peopleIndex:
while i < len(start) and start[i] <= p:
count += 1
i += 1
while j < len(end) and end[j] < p:
count -= 1
j += 1
res[index] = count
return resWhere is the size of the array , and is the size of the array .
class Solution:
def fullBloomFlowers(self, flowers: List[List[int]], people: List[int]) -> List[int]:
events = []
for start, end in flowers:
events.append((start, 1))
events.append((end + 1, -1))
events.sort()
queries = sorted((p, i) for i, p in enumerate(people))
res = [0] * len(people)
count = j = 0
for time, index in queries:
while j < len(events) and events[j][0] <= time:
count += events[j][1]
j += 1
res[index] = count
return resWhere is the size of the array , and is the size of the array .