Skip to content

Commit a4e9f25

Browse files
authored
Create 2540. Minimum Common Value (#425)
2 parents b72d874 + 72467c2 commit a4e9f25

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

2540. Minimum Common Value

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
class Solution {
2+
public:
3+
int getCommon(vector<int>& nums1, vector<int>& nums2) {
4+
int i = 0, j = 0;
5+
6+
int n1 = nums1.size(), n2 = nums2.size();
7+
8+
while (i < n1 && j < n2) {
9+
if (nums1[i] == nums2[j]) {
10+
return nums1[i];
11+
} else if (nums1[i] > nums2[j]) {
12+
j++;
13+
} else {
14+
i++;
15+
}
16+
}
17+
18+
return -1;
19+
}
20+
};

0 commit comments

Comments
 (0)