-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path2605.cpp
More file actions
28 lines (23 loc) · 705 Bytes
/
2605.cpp
File metadata and controls
28 lines (23 loc) · 705 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
// TC: O(n+m)
// SC: O(n+m)
class Solution {
public:
int minNumber(vector<int>& nums1, vector<int>& nums2) {
set<int> set1(nums1.begin(), nums1.end());
set<int> set2(nums2.begin(), nums2.end());
for (size_t digit = 1; digit <= 9; digit++) {
if (set1.count(digit) && set2.count(digit))
return digit;
}
int minDigit1 = 10, minDigit2 = 10;
for (auto e : nums1) {
if (minDigit1 > e)
minDigit1 = e;
}
for (auto e : nums2) {
if (minDigit2 > e)
minDigit2 = e;
}
return min(minDigit1 * 10 + minDigit2, minDigit2 * 10 + minDigit1);
}
};