update project structure
This commit is contained in:
		
							
								
								
									
										13
									
								
								.gitignore
									
									
									
									
										vendored
									
									
								
							
							
						
						
									
										13
									
								
								.gitignore
									
									
									
									
										vendored
									
									
								
							@@ -248,4 +248,15 @@ Module.symvers
 | 
				
			|||||||
Mkfile.old
 | 
					Mkfile.old
 | 
				
			||||||
dkms.conf
 | 
					dkms.conf
 | 
				
			||||||
 | 
					
 | 
				
			||||||
output/
 | 
					output/
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					# 忽略 Cargo 的编译输出目录
 | 
				
			||||||
 | 
					/target/
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					# 忽略 Cargo.lock(除非你是一个库)
 | 
				
			||||||
 | 
					# https://doc.rust-lang.org/cargo/faq.html#why-do-binaries-have-cargolock-in-version-control-but-not-libraries
 | 
				
			||||||
 | 
					Cargo.lock
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					# 忽略编译器和工具生成的文件
 | 
				
			||||||
 | 
					**/*.rs.bk
 | 
				
			||||||
 | 
					**/*.rs.old
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -2,8 +2,6 @@
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
一些算法题的仓库
 | 
					一些算法题的仓库
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					 | 
				
			||||||
[洛谷](https://www.luogu.com.cn/)
 | 
					[洛谷](https://www.luogu.com.cn/)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
[Leetcode](https://leetcode.com/)
 | 
					[Leetcode](https://leetcode.com/)
 | 
				
			||||||
 | 
					 | 
				
			||||||
 
 | 
				
			|||||||
							
								
								
									
										6
									
								
								leetcode_rs/Cargo.toml
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										6
									
								
								leetcode_rs/Cargo.toml
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,6 @@
 | 
				
			|||||||
 | 
					[package]
 | 
				
			||||||
 | 
					name = "leetcode_rs"
 | 
				
			||||||
 | 
					version = "0.1.0"
 | 
				
			||||||
 | 
					edition = "2021"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					[dependencies]
 | 
				
			||||||
							
								
								
									
										14
									
								
								leetcode_rs/src/main.rs
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										14
									
								
								leetcode_rs/src/main.rs
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,14 @@
 | 
				
			|||||||
 | 
					// src/main.rs
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					mod problem_1 {
 | 
				
			||||||
 | 
					    pub mod solution;
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					use problem_1::solution::Solution;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					fn main() {
 | 
				
			||||||
 | 
					    let nums = vec![2, 7, 11, 15];
 | 
				
			||||||
 | 
					    let target = 9;
 | 
				
			||||||
 | 
					    let result = Solution::two_sum(nums, target);
 | 
				
			||||||
 | 
					    println!("{:?}", result); // 输出: [0, 1]
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
@@ -1,5 +1,7 @@
 | 
				
			|||||||
use std::collections::HashMap;
 | 
					use std::collections::HashMap;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					pub struct Solution;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
impl Solution {
 | 
					impl Solution {
 | 
				
			||||||
    /// This function takes a vector of integers (`nums`) and an integer (`target`) as input.
 | 
					    /// This function takes a vector of integers (`nums`) and an integer (`target`) as input.
 | 
				
			||||||
    /// It returns a vector of integers.
 | 
					    /// It returns a vector of integers.
 | 
				
			||||||
@@ -15,7 +17,7 @@ impl Solution {
 | 
				
			|||||||
    pub fn two_sum(nums: Vec<i32>, target: i32) -> Vec<i32> {
 | 
					    pub fn two_sum(nums: Vec<i32>, target: i32) -> Vec<i32> {
 | 
				
			||||||
        let mut map = HashMap::new();
 | 
					        let mut map = HashMap::new();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        for (i, &num) in nums.iter_mut().enumerate() {
 | 
					        for (i, &num) in nums.iter().enumerate() {
 | 
				
			||||||
            let complement = target - num;
 | 
					            let complement = target - num;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            if let Some(&index) = map.get(&complement) {
 | 
					            if let Some(&index) = map.get(&complement) {
 | 
				
			||||||
		Reference in New Issue
	
	Block a user