File tree Expand file tree Collapse file tree 1 file changed +47
-0
lines changed
Expand file tree Collapse file tree 1 file changed +47
-0
lines changed Original file line number Diff line number Diff line change 1+ /*
2+ Author : Saransh Bangar
3+ Date : 09/03/2024
4+ Problem : Minimum Common Value
5+ Difficulty : Easy
6+ Problem Link : https://leetcode.com/problems/minimum-common-value/description/
7+ Video Solution : NA
8+ */
9+
10+
11+ class Solution {
12+ public:
13+ bool func (vector<int >& vec, int k)
14+ {
15+ int low=0 , high=vec.size ()-1 ;
16+ while (low<=high)
17+ {
18+ int mid=low+((high-low)/2 );
19+ if (vec[mid]==k)
20+ return true ;
21+ else if (vec[mid]>k)
22+ high=mid-1 ;
23+ else low=mid+1 ;
24+ }
25+ return false ;
26+ }
27+ int getCommon (vector<int >& nums1, vector<int >& nums2)
28+ {
29+ int ans;
30+ for (int i=0 , j=0 ;i<nums1.size () && j<nums2.size ();)
31+ {
32+ if (nums1[i]>nums2[j])
33+ {
34+ if (func (nums1, nums2[j]))
35+ return nums2[j];
36+ else j++;
37+ }
38+ else
39+ {
40+ if (func (nums2, nums1[i]))
41+ return nums1[i];
42+ else i++;
43+ }
44+ }
45+ return -1 ;
46+ }
47+ };
You can’t perform that action at this time.
0 commit comments