Skip to content

Commit 2cf3328

Browse files
committed
Added Form Smallest Number From Two Digit Arrays
1 parent 93de89d commit 2cf3328

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
class Solution {
2+
public int minNumber(int[] nums1, int[] nums2) {
3+
int[] counter = new int[10];
4+
int smallestOne = nums1[0];
5+
int smallestTwo = nums2[0];
6+
for (int num : nums1) {
7+
counter[num]++;
8+
smallestOne = Math.min(smallestOne, num);
9+
}
10+
for (int num : nums2) {
11+
counter[num]++;
12+
smallestTwo = Math.min(smallestTwo, num);
13+
}
14+
for (int i = 1; i < counter.length; i++) {
15+
if (counter[i] == 2) {
16+
return i;
17+
}
18+
}
19+
return Math.min(smallestOne, smallestTwo) * 10 + Math.max(smallestOne, smallestTwo);
20+
}
21+
}

0 commit comments

Comments
 (0)