Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitfc5ea09

Browse files
authored
Merge pull requestneetcode-gh#1985 from nirajvenkat/patch-4
Create 0704-binary-search.rs
2 parentsa82fd10 +034bd4c commitfc5ea09

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

‎rust/0704-binary-search.rs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
use std::cmp::Ordering::{Equal,Less,Greater};
2+
3+
implSolution{
4+
pubfnsearch(nums:Vec<i32>,target:i32) ->i32{
5+
let(mut l,mut r) =(0, nums.len());
6+
7+
while l < r{
8+
let m = l +(r - l) /2;
9+
match target.cmp(&nums[m]){
10+
Equal =>return masi32,
11+
Less => r = m,
12+
Greater => l = m +1,
13+
}
14+
}
15+
16+
-1
17+
}
18+
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp