pull down to refresh

My solution:
use std::collections::HashMap; pub fn two_sum(nums: Vec<i32>, target: i32) -> Vec<i32> { let mut map = HashMap::new(); for (i, &num) in nums.iter().enumerate() { let complement = target - num; if let Some(&index) = map.get(&complement) { return vec![index as i32, i as i32]; } map.insert(num, i); } vec![] } #[cfg(test)] mod tests { use super::*; #[test] fn test_example_1() { let nums = vec![1, 8, 10, 21]; let target = 18; assert_eq!(two_sum(nums, target), vec![1, 2]); } #[test] fn test_example_2() { let nums = vec![5, 12, 19, 3]; let target = 8; assert_eq!(two_sum(nums, target), vec![0, 3]); } #[test] fn test_example_3() { let nums = vec![6, 6]; let target = 12; assert_eq!(two_sum(nums, target), vec![0, 1]); } }
What language is this?
Edit: nevermind, I see in your post that you’re using Rust
reply
Yeah, I want to give it a real go. Try to get good at it to decide if it’s a language I want to use long term. Also thought of going through @jimmysong’s Programming Bitcoin book but doing it in rust instead of python. Could be fun.
reply