easy
arrays
binary-search
Given a sorted (ascending) array of integers nums and an integer target, return the index of target if it exists in nums, otherwise return -1.
Your solution should run in O(log n) time.
Examples
Example 1
Input: nums = [-1,0,3,5,9,12], target = 9
Output: 4
Example 2
Input: nums = [-1,0,3,5,9,12], target = 2
Output: -1
Example 3
Input: nums = [5], target = 5
Output: 0
Running will execute all 3 cases.