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 occurrence of that integer.
Example 1:
1 | Input: nums1 = [1,2,3], nums2 = [2,4] |
Example 2:
1 | Input: nums1 = [1,2,3,6], nums2 = [2,3,4,5] |
Constraints:
1 | 1 <= nums1.length, nums2.length <= 105 |
Approach
1 | Use the two pointers to go through both lists. |
Algorithm
1 | 1. Incresse the index1 if the current value of nums2 is larger. |
Implementation
1 | int getCommon(int* nums1, int nums1Size, int* nums2, int nums2Size){ |