Skip to content

Commit 4c43f8e

Browse files
committed
feat(leetcode): add No.2605
1 parent 5ad422d commit 4c43f8e

File tree

1 file changed

+30
-0
lines changed

1 file changed

+30
-0
lines changed
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
// https://leetcode.com/problems/form-smallest-number-from-two-digit-arrays/
2+
// algorithms
3+
// Easy (52.15%)
4+
// Total Accepted: 17K
5+
// Total Submissions: 32.6K
6+
7+
class Solution {
8+
9+
public int minNumber(int[] nums1, int[] nums2) {
10+
int minNum1 = 11, minNum2 = 11;
11+
int allExistNum = Integer.MAX_VALUE;
12+
Set<Integer> set1 = new HashSet<>();
13+
14+
for (int n : nums1) {
15+
set1.add(n);
16+
minNum1 = Math.min(minNum1, n);
17+
}
18+
19+
for (int n : nums2) {
20+
if (set1.contains(n)) {
21+
allExistNum = Math.min(allExistNum, n);
22+
}
23+
24+
minNum2 = Math.min(minNum2, n);
25+
}
26+
27+
return Math.min(allExistNum, minNum1 > minNum2 ? minNum2 * 10 + minNum1 : minNum1 * 10 + minNum2);
28+
}
29+
30+
}

0 commit comments

Comments
 (0)