aboutsummaryrefslogtreecommitdiff
path: root/min_common_value.py
blob: b959ff97745dca45093d65b25b8a49f87b94dcb3 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# 2540. Minimum Common Value

"""
given two integer arrays 'nums1' and 'nums2', sorted in non-decreasing order.
return the minimum integer common to both arrays. if there is no common
integer amongst 'nums1' and 'nums2', return -1. note that an integer is said
to be common to 'nums1' and 'nums2' if both arrays have at least one
occurence of that integer.
"""


class Solution(object):
    def getCommon(self, nums1, nums2):
        """
        :type nums1: List[int]
        :type nums2: List[int]
        :rtype: int
        """
        st = set(nums1) & set(nums2)
        return min(st) if len(st) else -1


if __name__ == "__main__":
    obj = Solution()
    print(obj.getCommon([1, 2, 3], [2, 4]))
    print(obj.getCommon([1, 2, 3, 6], [2, 3, 4, 5]))