Skip to content

Commit a488ebf

Browse files
authored
Added solution for 2605
1 parent a644a08 commit a488ebf

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
use std::cmp::min;
2+
3+
impl Solution {
4+
// Run a nested loop over both vectors. Initialize smallest_num as the biggest i32 value. If both numbers in the loop iteration are same, smallest_num should be the smallest of: smallest_num and the number in iteration. If both numbers in the loop iteration are different, smallest_num should be the smallest of: smallest_num and n1n2 and n2n1.
5+
pub fn min_number(nums1: Vec<i32>, nums2: Vec<i32>) -> i32 {
6+
let mut smallest_num = i32::MAX;
7+
for n1 in &nums1 {
8+
for n2 in &nums2 {
9+
if n1 == n2 {
10+
smallest_num = min(smallest_num, *n1);
11+
} else {
12+
smallest_num = min(min(((*n1 * 10) + *n2), ((*n2 * 10) + *n1)), smallest_num);
13+
}
14+
}
15+
}
16+
return smallest_num;
17+
}
18+
}

0 commit comments

Comments
 (0)