From 8219550ab5473d7b4803757725afb52bc1d539e9 Mon Sep 17 00:00:00 2001 From: Dale Seo <5466341+DaleSeo@users.noreply.github.com> Date: Sat, 28 Feb 2026 12:16:34 -0500 Subject: [PATCH] two-sum --- two-sum/DaleSeo.rs | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) create mode 100644 two-sum/DaleSeo.rs diff --git a/two-sum/DaleSeo.rs b/two-sum/DaleSeo.rs new file mode 100644 index 0000000000..6803aa8ff0 --- /dev/null +++ b/two-sum/DaleSeo.rs @@ -0,0 +1,17 @@ +use std::collections::HashMap; + +// TC: O(n) +// SC: O(n) +impl Solution { + pub fn two_sum(nums: Vec, target: i32) -> Vec { + let mut indices = HashMap::new(); + for (i, &num) in nums.iter().enumerate() { + let complement = target - num; + if let Some(&j) = indices.get(&complement) { + return vec![j as i32, i as i32]; + } + indices.insert(num, i); + } + vec![] + } +}