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 0e5ffe5 commit 8219550Copy full SHA for 8219550
two-sum/DaleSeo.rs
@@ -0,0 +1,17 @@
1
+use std::collections::HashMap;
2
+
3
+// TC: O(n)
4
+// SC: O(n)
5
+impl Solution {
6
+ pub fn two_sum(nums: Vec<i32>, target: i32) -> Vec<i32> {
7
+ let mut indices = HashMap::new();
8
+ for (i, &num) in nums.iter().enumerate() {
9
+ let complement = target - num;
10
+ if let Some(&j) = indices.get(&complement) {
11
+ return vec![j as i32, i as i32];
12
+ }
13
+ indices.insert(num, i);
14
15
+ vec![]
16
17
+}
0 commit comments