search first index with Binary Search(possible duplicate array)
2022年5月1日小于 1 分钟
search first index with Binary Search(possible duplicate array)
Question
This is a variation of 37. implement Binary Search (unique).
Your are given a sorted ascending array of number, but might have duplicates, you are asked to return the first index of a target number.
If not found return -1.
note
Please don't use Array.prototype.indexOf()
, it is not our goal.
Code
/**
* @param {number[]} arr - ascending array with duplicates
* @param {number} target
* @return {number}
*/
function firstIndex(arr, target){
// your code here
}
Related
- implement Binary Search (unique)
- 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)