Advertisement
serega1112

350

Dec 13th, 2020
66
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 intersect(self, nums1: List[int], nums2: List[int]) -> List[int]:
  3.        
  4.         nums1.sort()
  5.         nums2.sort()
  6.         p1 = 0
  7.         p2 = 0
  8.         res = []
  9.        
  10.         while p1 < len(nums1) and p2 < len(nums2):
  11.             if nums1[p1] == nums2[p2]:
  12.                 res.append(nums1[p1])
  13.                 p1 += 1
  14.                 p2 += 1
  15.             elif nums1[p1] < nums2[p2]:
  16.                 p1 += 1
  17.             else:
  18.                 p2 += 1
  19.                
  20.         return res
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement