Skip to content

Instantly share code, notes, and snippets.

@ridv
Last active May 25, 2020 09:48
Show Gist options
  • Save ridv/5bd33d1cd2786b20b2f7f5ebe4f8a5be to your computer and use it in GitHub Desktop.
Save ridv/5bd33d1cd2786b20b2f7f5ebe4f8a5be to your computer and use it in GitHub Desktop.
use std::collections::HashMap;
impl Solution {
pub fn two_sum(nums: Vec<i32>, target: i32) -> Vec<i32> {
let mut lookup = HashMap::new();
for i in 0..nums.len() {
let key = &(target- nums[i]);
if lookup.contains_key(key) {
return vec![*lookup.get(key).unwrap(), (i as i32)];
}
lookup.insert(nums[i], (i as i32));
}
return vec![];
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment