Skip to content

Commit 9091dec

Browse files
authored
Create 2070.py
1 parent 713699a commit 9091dec

File tree

1 file changed

+26
-0
lines changed

1 file changed

+26
-0
lines changed

python3/2070.py

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
class Solution:
2+
def maximumBeauty(self, items: List[List[int]], queries: List[int]) -> List[int]:
3+
# calculate max beauty for each price in items
4+
beautyMap = defaultdict(int)
5+
maxVal = 0
6+
items.sort()
7+
for x, y in items:
8+
maxVal = max(maxVal, y)
9+
beautyMap[x] = max(beautyMap[x], maxVal)
10+
11+
# binary search
12+
prices = list(beautyMap.keys())
13+
res = []
14+
for q in queries:
15+
if q < prices[0]:
16+
res.append(0)
17+
continue
18+
l, r = 0, len(prices) - 1
19+
while l < r:
20+
m = (l + r + 1) // 2
21+
if prices[m] <= q:
22+
l = m
23+
else:
24+
r = m - 1
25+
res.append(beautyMap[prices[l]])
26+
return res

0 commit comments

Comments
 (0)