mirror of
https://github.com/krahets/hello-algo.git
synced 2026-08-10 02:50:59 +00: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,8 @@
|
||||
/**
|
||||
/*
|
||||
* File: binary_search.rs
|
||||
* Created Time: 2023-02-05
|
||||
* Author: sjinzh (sjinzh@gmail.com)
|
||||
*/
|
||||
*/
|
||||
|
||||
/* 二分查找(双闭区间) */
|
||||
fn binary_search(nums: &[i32], target: i32) -> i32 {
|
||||
@@ -49,11 +49,11 @@ pub fn main() {
|
||||
let target = 6;
|
||||
let nums = [ 1, 3, 6, 8, 12, 15, 23, 67, 70, 92 ];
|
||||
|
||||
/* 二分查找(双闭区间) */
|
||||
// 二分查找(双闭区间)
|
||||
let mut index = binary_search(&nums, target);
|
||||
println!("目标元素 6 的索引 = {index}");
|
||||
|
||||
/* 二分查找(左闭右开) */
|
||||
// 二分查找(左闭右开)
|
||||
index = binary_search1(&nums, target);
|
||||
println!("目标元素 6 的索引 = {index}");
|
||||
}
|
||||
Reference in New Issue
Block a user