Skip to content

Commit 165b66e

Browse files
committed
O(n+m) time using two pointer
1 parent ded3bd4 commit 165b66e

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
class Solution:
2+
def getCommon(self, nums1: List[int], nums2: List[int]) -> int:
3+
i, j = 0, 0
4+
while i < len(nums1) and j < len(nums2):
5+
if nums1[i] < nums2[j]:
6+
i += 1
7+
elif nums1[i] > nums2[j]:
8+
j += 1
9+
else:
10+
return nums1[i]
11+
return -1

0 commit comments

Comments
 (0)