-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
30 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
'use strict'; | ||
|
||
function solution(arr, m) { | ||
let answer = 0; | ||
arr.sort((a,b) => a-b); | ||
|
||
let left = 0; | ||
let right = arr.length-1; | ||
|
||
while(left <= right) { | ||
let mid = parseInt((left+right)/2); | ||
if(arr[mid] === m) { | ||
answer = mid + 1; | ||
break; | ||
} else if(arr[mid] > m) { | ||
right = mid - 1; | ||
} else { | ||
left = mid + 1; | ||
} | ||
} | ||
return answer; | ||
} | ||
|
||
let arr = [23, 87, 65, 12, 57, 32, 99, 81]; | ||
console.log(solution(arr, 32)); | ||
|
||
/* | ||
- 이분검색은 정렬한 배열에서 중간 값을 이용해 주어진 값을 찾는 알고리즘 | ||
*/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -20,6 +20,6 @@ | |
|7|△|O| | ||
|8|△|O| | ||
|9|△|O| | ||
|10|△|한번 더 풀기| | ||
|10|△|O| | ||
|11|X|예정| | ||
|12|X|예정| |