neetcode-gh/leetcode

Bug Report for binary-search

Closed this issue · 1 comments

Bug Report for https://neetcode.io/problems/binary-search

Please describe the bug below and include any steps to reproduce the bug or screenshots if possible.

class Solution {
/**
* @param {number[]} nums
* @param {number} target
* @return {number}
*/
search(nums, target) {
// There is no built in function for JS.
return nums.indexOf(target);
}
}

Correction => There is a built-in function for JS.

Additional information => we can also calculate mid by this formula , which I felt more easier

let mid = Math.floor((start + end)/2);

Thanks for the feedback! There is no built in function as binarySearch() in JAVA. But you are telling that to use Math.floor() which is just used to find mid and not similar to binarySearch() function.