My Modified Binary Search Java Solution with edge cases handling


  • 0
    R
      static int modifiedBinarySearch(int arr[], int num, int start, int end) {
            if (start > end) return start;
            int mid = start + (end - start) / 2;
            if (mid >= arr.length) return arr.length;
            if (arr[mid] == num) {
                return mid;
            } else if (arr[mid] > num) {
                return modifiedBinarySearch(arr, num, start, mid - 1);
            } else {
                return modifiedBinarySearch(arr, num, mid + 1, end);
            }
        ```

Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.