Skip to content

Commit

Permalink
O(n+m) time using two pointer
Browse files Browse the repository at this point in the history
  • Loading branch information
149ps committed Mar 9, 2024
1 parent ded3bd4 commit 165b66e
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions 2540. Minimum Common Value/2540. Minimum Common Value_1.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
class Solution:
def getCommon(self, nums1: List[int], nums2: List[int]) -> int:
i, j = 0, 0
while i < len(nums1) and j < len(nums2):
if nums1[i] < nums2[j]:
i += 1
elif nums1[i] > nums2[j]:
j += 1
else:
return nums1[i]
return -1

0 comments on commit 165b66e

Please sign in to comment.