rust 项目结构
This commit is contained in:
parent
2f42f77465
commit
99f87458bc
|
@ -1,36 +1,20 @@
|
|||
use std::collections::HashMap;
|
||||
|
||||
pub struct ListNode {
|
||||
pub val: i32,
|
||||
pub next: Option<Box<ListNode>>,
|
||||
}
|
||||
|
||||
impl ListNode {
|
||||
#[inline]
|
||||
fn new(val: i32) -> Self {
|
||||
ListNode {
|
||||
next: None,
|
||||
val,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
use crate::structure::*;
|
||||
pub struct Solution {}
|
||||
|
||||
impl Solution {
|
||||
/// 1. 两数之和
|
||||
///
|
||||
/// 给定一个整数数组 nums 和一个目标值 target,请你在该数组中找出和为目标值的那 两个 整数,并返回他们的数组下标。
|
||||
///
|
||||
/// 你可以假设每种输入只会对应一个答案。但是,数组中同一个元素不能使用两遍。
|
||||
/// # Examples
|
||||
///
|
||||
/// ```
|
||||
/// use my_leetcode::leet_code::Solution;
|
||||
/// let s = Solution::two_sum(vec![2, 7, 11, 15], 9);
|
||||
/// assert_eq!(s, vec![0, 1]);
|
||||
/// ```
|
||||
///
|
||||
pub fn two_sum(nums: Vec<i32>, target: i32) -> Vec<i32> {
|
||||
let mut m: HashMap<i32, i32> = HashMap::new();
|
||||
let mut m = std::collections::HashMap::new();
|
||||
for (i, v) in nums.into_iter().enumerate() {
|
||||
if m.contains_key(&v) {
|
||||
return vec![m[&v], i as i32];
|
||||
|
@ -40,10 +24,10 @@ impl Solution {
|
|||
vec![]
|
||||
}
|
||||
|
||||
pub fn add_two_numbers(l1: Option<Box<ListNode>>, l2: Option<Box<ListNode>>) -> Option<Box<ListNode>> {}
|
||||
//pub fn add_two_numbers(l1: Option<Box<ListNode>>, l2: Option<Box<ListNode>>) -> Option<Box<ListNode>> {}
|
||||
}
|
||||
|
||||
///单元测试
|
||||
// 单元测试
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
|
|
23
src/lib.rs
23
src/lib.rs
|
@ -0,0 +1,23 @@
|
|||
// lib注释
|
||||
//! 我的rust版本leetcode代码
|
||||
//! # Quick start
|
||||
//!
|
||||
//!
|
||||
|
||||
// Re-exports 从依赖库重新导出的模块
|
||||
//pub use std::collections::hash_map;
|
||||
|
||||
// Public modules 导出模块
|
||||
#[allow(unused)]
|
||||
pub mod leet_code;
|
||||
#[allow(unused)]
|
||||
pub mod structure;
|
||||
|
||||
// Public exports
|
||||
|
||||
|
||||
// 单元测试
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
}
|
|
@ -1,6 +1,3 @@
|
|||
#[allow(unused)]
|
||||
mod leet_code;
|
||||
|
||||
fn main() {
|
||||
println!("Hello, world!");
|
||||
}
|
||||
|
|
|
@ -0,0 +1,15 @@
|
|||
/// 单链表
|
||||
pub struct ListNode {
|
||||
pub val: i32,
|
||||
pub next: Option<Box<ListNode>>,
|
||||
}
|
||||
|
||||
impl ListNode {
|
||||
#[inline]
|
||||
fn new(val: i32) -> Self {
|
||||
ListNode {
|
||||
next: None,
|
||||
val,
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue