Advertisement
serega1112

34

Dec 13th, 2020
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.52 KB | None | 0 0
  1. class Solution:
  2.     def intervalIntersection(self, A: List[List[int]], B: List[List[int]]) -> List[List[int]]:
  3.        
  4.         p1 = 0
  5.         p2 = 0
  6.         res = []
  7.        
  8.         while p1 < len(A) and p2 < len(B):
  9.             start = max(A[p1][0], B[p2][0])
  10.             end = min(A[p1][1], B[p2][1])
  11.             if start <= end:
  12.                 res.append([start, end])
  13.             if A[p1][1] < B[p2][1]:
  14.                 p1 += 1
  15.             else:
  16.                 p2 += 1
  17.                
  18.         return res
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement