mirror of
https://github.com/krahets/hello-algo.git
synced 2025-11-02 12:58:42 +08:00
Refine some details and coding style for Rust codes (#344)
* Refine some details and coding style for Rust codes * Update coding style for Rust codes * Update time_complexity.rs * Update array.rs * Update leetcode_two_sum.rs * Update hash_map.rs * Update file headers * Update coding style for Rust codes and Zig codes * Update coding style for Rust codes and Zig codes --------- Co-authored-by: Yudong Jin <krahets@163.com>
This commit is contained in:
@ -1,8 +1,10 @@
|
||||
/**
|
||||
/*
|
||||
* File: leetcode_two_sum.rs
|
||||
* Created Time: 2023-01-14
|
||||
* Author: xBLACICEx (xBLACKICEx@outlook.com), sjinzh (sjinzh@gmail.com)
|
||||
*/
|
||||
*/
|
||||
|
||||
include!("../include/include.rs");
|
||||
|
||||
use std::collections::HashMap;
|
||||
struct SolutionBruteForce;
|
||||
@ -49,9 +51,9 @@ fn main() {
|
||||
// 方法一
|
||||
let res = SolutionBruteForce::two_sum(&nums, target);
|
||||
print!("方法一 res = ");
|
||||
inc::print_util::print_array(&res);
|
||||
print_util::print_array(&res);
|
||||
// 方法二
|
||||
let res = SolutionHashMap::two_sum(&nums, target);
|
||||
print!("\n方法二 res = ");
|
||||
inc::print_util::print_array(&res);
|
||||
}
|
||||
print_util::print_array(&res);
|
||||
}
|
||||
|
||||
@ -1,8 +1,8 @@
|
||||
/**
|
||||
/*
|
||||
* File: time_complexity.rs
|
||||
* Created Time: 2023-01-10
|
||||
* Author: xBLACICEx (xBLACKICEx@outlook.com), sjinzh (sjinzh@gmail.com)
|
||||
*/
|
||||
*/
|
||||
|
||||
/* 常数阶 */
|
||||
fn constant(n: i32) -> i32 {
|
||||
@ -167,4 +167,4 @@ fn main() {
|
||||
|
||||
count = factorial_recur(n);
|
||||
println!("阶乘阶(递归实现)的计算操作数量 = {}", count);
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,9 +1,11 @@
|
||||
/**
|
||||
/*
|
||||
* File: time_complexity.rs
|
||||
* Created Time: 2023-01-13
|
||||
* Author: xBLACICEx (xBLACKICEx@outlook.com), sjinzh (sjinzh@gmail.com)
|
||||
*/
|
||||
|
||||
include!("../include/include.rs");
|
||||
|
||||
use rand::seq::SliceRandom;
|
||||
use rand::thread_rng;
|
||||
|
||||
@ -35,7 +37,7 @@
|
||||
let nums = random_numbers(n);
|
||||
let index = find_one(&nums).unwrap();
|
||||
print!("\n数组 [ 1, 2, ..., n ] 被打乱后 = ");
|
||||
inc::print_util::print_array(&nums);
|
||||
print_util::print_array(&nums);
|
||||
println!("\n数字 1 的索引为 {}", index);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user