We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 53ce7c7 commit a635756Copy full SHA for a635756
two-sum/livemehere.rs
@@ -0,0 +1,17 @@
1
+use std::collections::HashMap;
2
+
3
+impl Solution {
4
+ pub fn two_sum(nums: Vec<i32>, target: i32) -> Vec<i32> {
5
+ let mut map: HashMap<i32, i32> = HashMap::new();
6
7
+ for (idx, &n) in nums.iter().enumerate() {
8
+ let pair = target - n;
9
+ if let Some(&pair_idx) = map.get(&pair) {
10
+ return vec![idx as i32, pair_idx];
11
+ } else {
12
+ map.insert(n, idx as i32);
13
+ }
14
15
+ vec![]
16
17
+}
0 commit comments