Friday, 31 March 2023

Daily LeetCoding Challenge April, Day 1

 JAVA CODE-

class Solution {

    public int search(int[] nums, int target) {

        int low = 0, high = nums.length - 1;

        while (low <= high) {

            int mid = (high - low) / 2 + low;

            int num = nums[mid];

            if (num == target)

                return mid;

            else if (num > target)

                high = mid - 1;

            else

                low = mid + 1;

        }

        return -1;

    }

}

No comments:

Post a Comment

Daily LeetCoding Challenge April, Day 1

 JAVA CODE- class Solution {     public int search(int[] nums, int target) {         int low = 0, high = nums.length - 1;         while (low...