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

Commit138fe15

Browse files
Create 0704-binary-search.scala
1 parent8de25ca commit138fe15

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

‎scala/0704-binary-search.scala

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
objectSolution {
2+
defsearch(nums:Array[Int],target:Int):Int= {
3+
varleft=0
4+
varright= nums.length-1
5+
6+
while (left<= right) {
7+
valmid= left+ (right- left)/2
8+
9+
if (nums(mid)== target) {
10+
return mid
11+
}elseif (nums(mid)< target) {
12+
left= mid+1
13+
}else {
14+
right= mid-1
15+
}
16+
}
17+
18+
return-1
19+
}
20+
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp