Implement a binary search algorithm that finds the index of a target value in a sorted array. If the target value is not found, return -1.
nums.target to search for.target in nums or -1 if target is not present.Example 1:
Input: nums = [1, 2, 3, 4, 5], target = 3
Output: 2
Example 2:
Input: nums = [1, 2, 3, 4, 5], target = 6
Output: -1
1 <= nums.length <= 10^4-10^9 <= nums[i] <= 10^9nums is sorted in ascending order.nums = [1, 2, 3, 4, 5], target = 3Output2WhyThe target 3 is found at index 2.nums = [1, 2, 3, 4, 5], target = 6Output-1WhyThe target 6 is not present in the array.1 <= nums.length <= 10^4-10^9 <= nums[i] <= 10^9nums is sorted in ascending order.def binary_search(nums: list[int], target: int) -> int: