implement Binary Search (unique)
2022年5月1日小于 1 分钟
implement Binary Search (unique)
Question
Even in Front-End review, basic algorithm technique like Binary Search are likely to be asked.
You are given an unique & ascending array of integers, please search for its index with Binary Search.
If not found, return -1
note
Please don't use Array.prototype.indexOf()
, it is not our goal.
Code
/**
* @param {number[]} arr - ascending unique array
* @param {number} target
* @return {number}
*/
function binarySearch(arr, target){
// your code here
}
Related
- search first index with Binary Search(possible duplicate array)
- search last index with Binary Search(possible duplicate array)
- search element right before target with Binary Search(possible duplicate array)
- search element right after target with Binary Search(possible duplicate array)