Given two integer arrays nums1 and nums2, each sorted in non-decreasing order, return the minimum integer that appears in both arrays. If no integer is common to both, return -1.
Given two integer arrays nums1 and nums2, each sorted in non-decreasing order, return the minimum integer that appears in both arrays. If no integer is common to both, return -1.
Example 1:
Input: {"nums1":[1,2,3],"nums2":[2,4]}
Output: 2
Constraints:
1≤nums1.length,nums2.length≤105
1≤nums1[i],nums2[j]≤109
Both nums1 and nums2 are sorted in non-decreasing order.
Test Cases
Input (Stdin)
Expected Output (Stdout)
Execution Result
Run code to see results.
Input
arr ={"nums1":[1,2,3],"nums2":[2,4]}
Both arrays are sorted. Put i at the start of nums1 and j at the start of nums2; the first value they agree on is the smallest common value.