-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
22 lines (20 loc) · 887 Bytes
/
main.py
File metadata and controls
22 lines (20 loc) · 887 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
class Solution(object):
def intervalIntersection(self, firstList, secondList):
"""
:type firstList: List[List[int]]
:type secondList: List[List[int]]
:rtype: List[List[int]]
"""
i = 0
j = 0
result = []
while i < len(firstList) and j < len(secondList):
a_start, a_end = firstList[i]
b_start, b_end = secondList[j]
if a_start <= b_end and b_start <= a_end: # Criss-cross lock
result.append([max(a_start, b_start), min(a_end, b_end)]) # Squeezing
if a_end <= b_end: # Exhausted this range in A
i += 1 # Point to next range in A
else: # Exhausted this range in B
j += 1 # Point to next range in B
return result