2540.cpp (407B)
1 class Solution { 2 public: 3 int getCommon(const vector<int> &nums1, const vector<int> &nums2) const { 4 const int n = size(nums1), m = size(nums2); 5 6 int i = 0, j = 0; 7 while (i < n && j < m) { 8 if (nums1[i] == nums2[j]) return nums1[i]; 9 if (nums1[i] > nums2[j]) 10 j++; 11 else 12 i++; 13 } 14 15 return -1; 16 } 17 };