first commit

This commit is contained in:
2025-10-19 16:43:45 +08:00
parent d3cb2a9843
commit 1d411cefb5
4 changed files with 27 additions and 80 deletions

View File

@@ -3,7 +3,21 @@
* Licensed under the MIT License. See https://go.microsoft.com/fwlink/?linkid=2090316 for license information.
*-------------------------------------------------------------------------------------------------------------*/
fn two_sum(nums: Vec<i32>, target: i32) -> Vec<i32> {
use std::collections::HashMap;
let mut map = HashMap::new();
for (i, &num) in nums.iter().enumerate() {
if let Some(&j) = map.get(&(target - num)) {
return vec![j as i32, i as i32];
}
map.insert(num, i);
}
vec![]
}
fn main() {
let name = "VS Code Remote - Containers";
println!("Hello, {}!", name);
let nums = vec![2, 7, 11, 15];
let target = 9;
let result = two_sum(nums, target);
println!("{:?}", result); // 输出: [0, 1]
}