FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
python-for-coding-test/15/2.java at master · ndb796/python-for-coding-test · GitHub
ndb796
/
python-for-coding-test
Public
Notifications
You must be signed in to change notification settings
Fork
831
Star
2.4k
Code
Issues
129
Pull requests
1
Actions
Projects
Security and quality
0
Insights
Additional navigation options
Code
Issues
Pull requests
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
python-for-coding-test
/
15
/
2.java
Copy path
More file actions
More file actions
Latest commit
History
History
History
32 lines (26 loc) · 1.05 KB
Breadcrumbs
python-for-coding-test
/
15
/
2.java
Copy path
File metadata and controls
32 lines (26 loc) · 1.05 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
import
java
.
util
.*;
public
class
Main
{
// 이진 탐색 소스코드 구현(재귀 함수)
public
static
int
binarySearch
(
int
[]
arr
,
int
start
,
int
end
) {
if
(
start
>
end
)
return
-
1
;
int
mid
= (
start
+
end
) /
2
;
// 고정점을 찾은 경우 중간점 인덱스 반환
if
(
arr
[
mid
] ==
mid
)
return
mid
;
// 중간점의 값보다 중간점이 작은 경우 왼쪽 확인
else
if
(
arr
[
mid
] >
mid
)
return
binarySearch
(
arr
,
start
,
mid
-
1
);
// 중간점의 값보다 중간점이 큰 경우 오른쪽 확인
else
return
binarySearch
(
arr
,
mid
+
1
,
end
);
}
public
static
void
main
(
String
[]
args
) {
Scanner
sc
=
new
Scanner
(
System
.
in
);
int
n
=
sc
.
nextInt
();
int
[]
arr
=
new
int
[
n
];
for
(
int
i
=
0
;
i
<
n
;
i
++) {
arr
[
i
] =
sc
.
nextInt
();
}
// 이진 탐색(Binary Search) 수행
int
index
=
binarySearch
(
arr
,
0
,
n
-
1
);
// 결과 출력
System
.
out
.
println
(
index
);
}
}
Back
|
FazBrowse Home
|
New Git URL