MCPcopy Create free account
hub / github.com/Ainevsia/Leetcode-Rust / two_sum

Method two_sum

1. Two Sum/src/main.rs:8–19  ·  view source on GitHub ↗
(nums: Vec<i32>, target: i32)

Source from the content-addressed store, hash-verified

6
7impl Solution {
8 pub fn two_sum(nums: Vec<i32>, target: i32) -> Vec<i32> {
9 use std::collections::HashMap;
10 let mut map: HashMap<i32, i32> = HashMap::new();
11 for i in 0..nums.len() {
12 let pair = target - nums[i];
13 match map.get(&pair) {
14 None => { map.insert(nums[i], i as i32); }
15 Some(&idx) => { return vec![idx, i as i32] }
16 }
17 }
18 unimplemented!()
19 }
20}
21
22#[cfg(test)]

Callers

nothing calls this directly

Calls 2

getMethod · 0.45
insertMethod · 0.45

Tested by

no test coverage detected