-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSolution.cs
More file actions
24 lines (23 loc) · 755 Bytes
/
Solution.cs
File metadata and controls
24 lines (23 loc) · 755 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
namespace LeetCode.Problem2605{
//2605. Form Smallest Number From Two Digit Arrays
//https://leetcode.com/problems/form-smallest-number-from-two-digit-arrays/
/*
Given two arrays of unique digits nums1 and nums2,
return the smallest number that contains at least one digit from each array.
*/
public class Solution {
public int MinNumber(int[] nums1, int[] nums2) {
int first = 0;
int[] sorted = nums1.OrderBy(p => p).ToArray();
for (int i = 0; i < nums1.Length; i++)
{
first = sorted[i];
if (nums2.Contains(first))
return first;
}
first = nums1.Min();
var second = nums2.Min();
return Math.Min(first,second) * 10 + Math.Max(first,second);
}
}
}