Gary Lai
  • Home
  • About
  • Backtrack
Sign in Subscribe

2540. Minimum Common Value

Last updated on  Oct 31, 2025

2540. Minimum Common Value

class Solution:
    def getCommon(self, nums1: List[int], nums2: List[int]) -> int:
        
        i1 = 0
        i2 = 0

        while i1 < len(nums1) and i2 < len(nums2):
            if nums1[i1] == nums2[i2]:
                return nums1[i1]
            
            if nums1[i1] > nums2[i2]:
                i2 += 1
            else:
                i1 += 1
        
        return -1
Previous 967. Numbers With Same Consecutive Differences
Next 2000. Reverse Prefix of Word
Gary Lai © 2025
  • Sign up
Powered by Ghost