1
Fork 0
leetcode/source/two_sum/mod.rs

18 lines
422 B
Rust
Raw Permalink Normal View History

2022-04-06 12:30:31 +00:00
use std::convert::TryInto;
pub fn two_sum(numbers: Vec<i32>, target: i32) -> Vec<i32> {
for (index_1, number_1) in numbers.iter().enumerate() {
for (index_2, number_2) in numbers.iter().enumerate() {
if index_1 == index_2 {
continue;
}
if number_1 + number_2 == target {
return vec![index_1.try_into().unwrap(), index_2.try_into().unwrap()];
}
}
}
unreachable!()
2022-04-06 12:30:31 +00:00
}