Skip to content

Commit

Permalink
#21 22.07.28 > 이진탐색 > 정렬된 배열에서 특정 수의 개수 구하기
Browse files Browse the repository at this point in the history
  • Loading branch information
beurmuz committed Jul 28, 2022
1 parent a277986 commit 86e7957
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/cote/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@
|2|[구현](./implementation/)|[상하좌우](./implementation/imple_ex01.js)<br>[시각](./implementation/imple_ex02.js)<br>[왕실의 나이트](./implementation/imple_01.js)<br>[게임 개발](./implementation/imple_02.js)<br>-<br>[럭키 스트레이트](./implementation/test_01.js)<br>[문자열 재정렬](./implementation/test_02.js)<br>|22.07.15<br><br><br><br>-<br>22.07.20<br>22.07.23<br>|△<br>△<br>△<br>X<br>-<br>O<br>O|[22.07.17](./implementation/../replay_01.js)<br>[22.07.18](./implementation/replay_02.js)<br>[22.07.19](./implementation//replay_03.js)<br>[22.07.19](./implementation/replay_04.js)<br>-<br>X<br>X|
|3|[DFS, BFS](./dfs%2Cbfs/)|[DFS 예제](./dfs%2Cbfs/dfs_ex.js)<br>[BFS 예제](./dfs%2Cbfs/dfs_ex.js)<br>[음료수 얼려 먹기](./dfs%2Cbfs/dfs%2Cbfs_01.js)<br>[미로 탈출](./dfs%2Cbfs/dfs%2Cbfs_02.js)<br>-<br>응|22.07.15<br><br>22.07.21<br>22.07.22<br>-<br>응|O<br>O<br>X<br>X<br>-<br>응|O<br>O<br>O<br>O<br>-<br>ㅇ|
|4|[정렬](./sort/)|[위에서 아래로](./sort/sort_ex_01.js)<br>[성적이 낮은 순서로 학생 출력하기](./sort/sort_ex_02.js)<br>[두 배열의 원소 교체](./sort/sort_ex_03.js)<br>-<br>[국영수](./sort/test_01.js)<br>[안테나](./sort/test_02.js)|22.07.22<br>22.07.24<br><br>-<br>22.07.25<br>22.07.28<br>|O<br>O<br>O<br>-<br>O<br>O|X<br>X<br>X<br>-<br>O<br>X|
|5|[이진 탐색](./binarySearch/)|[부품 찾기](./binarySearch/ex_01.js)<br>[떡볶이 떡 만들기](./binarySearch/ex_02.js)<br>|22.07.27<br><br>|X<br>O|O<br>X|
|5|[이진 탐색](./binarySearch/)|[부품 찾기](./binarySearch/ex_01.js)<br>[떡볶이 떡 만들기](./binarySearch/ex_02.js)<br>-<br>[정렬된 배열에서 특정 수의 개수 구하기](./binarySearch/test_01.js)<br>|22.07.27<br><br>-<br>22.07.28<br>|X<br>O<br>-<br>X<br>|O<br>X<br>-<br>O|
15 changes: 15 additions & 0 deletions src/cote/binarySearch/test_01.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
'use strict';

function solution(n, x, arr) {
let count = 0;
function binarySearch(arr, target, start, end) {
let mid = Math.ceil(start+end/2);
if(arr[mid] === target) count++;
if(arr[mid] > target) end = mid - 1;
else if(arr[mid] < target) start = mid + 1;
}
return count;
}

const numberList = [1, 1, 2, 2, 2, 2, 3];
console.log(solution(7, 2, numberList));

0 comments on commit 86e7957

Please sign in to comment.