Skip to content

Commit a4c5d4d

Browse files
authored
Added solution for 2160
1 parent 25dac24 commit a4c5d4d

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
impl Solution {
2+
// Split number into Vec<char> and then sort the characters. Then generate two 2-digit numbers, first number using the 1st and 3rd digit, second number using the 2nd and 4th digit. These will be the smallest two 2-digit numbers possible using these digits. Then return their sum
3+
pub fn minimum_sum(num: i32) -> i32 {
4+
let string = num.to_string();
5+
let mut char_vec: Vec<char> = string.chars().collect();
6+
char_vec.sort();
7+
let first_num: i32 = [char_vec[0], char_vec[2]].iter().collect::<String>().parse().unwrap();
8+
let second_num: i32 = [char_vec[1], char_vec[3]].iter().collect::<String>().parse().unwrap();
9+
return (first_num + second_num);
10+
}
11+
}

0 commit comments

Comments
 (0)