You are given a sorted array of integers called nums and an integer target.
Your task is to search for target within nums.
You may assume that:
nums is sorted in ascending order.Return the index of target if found, or -1 otherwise.
nums = [1, 3, 5, 7, 9]
target = 5
2
The target 5 is at index 2 in the array.
nums = [2, 4, 6, 8, 10]
target = 7
-1
The target 7 does not exist in the array.
nums = [0, 1, 2, 3, 4, 5]
target = 0
0
The target 0 is at the very first index.
nums = [1, 3, 5, 7, 9]
target = 5
2