436. 寻找右区间

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
class Solution:
def findRightInterval(self, intervals: List[List[int]]) -> List[int]:
ans = []
tool_list = sorted(list(enumerate(intervals)),key=lambda x:x[1][0])
start_list = []
for ele in intervals:
start_list.append(ele[0])
start_list.sort()
print(tool_list,"\n",start_list)
for ele in intervals:
j_idx = bisect.bisect_left(start_list,ele[1])
if j_idx<len(tool_list) and j_idx>=0:
ans.append(tool_list[j_idx][0])
else:
ans.append(-1)
return ans